From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: ozzloy Newsgroups: gmane.emacs.bugs Subject: bug#63941: [PATCH] ; always CRLF before non-first boundary in multipart form Date: Sat, 10 Jun 2023 18:38:44 -0700 Message-ID: References: <837csf4fp8.fsf@gnu.org> <83jzwe32pj.fsf@gnu.org> <83sfazzm8x.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000a19f8805fdd0aa5d" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34859"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63941@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 11 03:40:31 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q8A4E-0008ti-Mj for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Jun 2023 03:40:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q8A3o-0006uk-JH; Sat, 10 Jun 2023 21:40:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q8A3n-0006uX-2O for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2023 21:40:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q8A3m-0002ES-PY for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2023 21:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q8A3m-0006pZ-2t for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2023 21:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: ozzloy Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Jun 2023 01:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63941 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63941-submit@debbugs.gnu.org id=B63941.168644755226194 (code B ref 63941); Sun, 11 Jun 2023 01:40:02 +0000 Original-Received: (at 63941) by debbugs.gnu.org; 11 Jun 2023 01:39:12 +0000 Original-Received: from localhost ([127.0.0.1]:36472 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q8A2x-0006oO-88 for submit@debbugs.gnu.org; Sat, 10 Jun 2023 21:39:11 -0400 Original-Received: from mail-oi1-f180.google.com ([209.85.167.180]:51572) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q8A2t-0006o5-J5 for 63941@debbugs.gnu.org; Sat, 10 Jun 2023 21:39:09 -0400 Original-Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-39cc64e4a22so171694b6e.3 for <63941@debbugs.gnu.org>; Sat, 10 Jun 2023 18:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686447541; x=1689039541; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yd5a5vjCxnH7wasvb+bHZXVjgC59MIPjaueALNPuPb0=; b=Cy3BOBOlRJuMENI/H96+E3wQVEQ5LbVHTVjReW3nU5mCIq0n3zIbgluuNr6aIuh+Yg aWIhOYmEcXthFynUPzEsByKz+TwyTeuHOoVmjQjkCCPNONFv4dzqyVkS966EhrmoAIOn S2e1BoxlPkRGhkIFD/vKq9YP4SOnybAWP9aOFWmNRvWhbyj9K9u+DpNUI32ZEByTRXyC x8fMc9aWwcjAkTI9z0Wo/srGaYfXgqKAOZluqx+yP3kQykeo4SraweANpSFAMVOgDrDX 0VSRvxWAgk9BVxftSHpwD6XX65g/WuUP6L+y7QL83nNjug8vYUUhnotA60G16qDX1Ibu bdaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686447541; x=1689039541; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yd5a5vjCxnH7wasvb+bHZXVjgC59MIPjaueALNPuPb0=; b=j3Qfm1JUaAbK6+mji/AY81ozpm+5q0wJX8XBNUFH0qTyL0VkpiKZXeEPZswSF5q1Wj QjliB/xdKMoWsHUkTx2HWmCm+QjakGa99mc8Mij6MOD56ZZZ4BoKPRSPlGhzHKsNIYUA ewLfAtAz6rONy1q1rbePN9cahWM3S8rZQv0t15t6MI3bQSnmFGFm0Edvkmi378nrv2NY GJ8uxbymFZhT/20A2QlkpPkWnhXJ4dEdTzknbr6VHs8OZ2Wv3te+c0v01xwlGu7bVp8E LBrqw+420Zx+P9qSWO4RvYn5UfZNFXFMsHNBdvDsTTfihLhPQHl3nhPGjvekMruQtdIe pzAQ== X-Gm-Message-State: AC+VfDyDfdDJyYYqCSRpxM6uXT0GBZgaDLR/4E1A+lpAtfVqaXmqL9Dd RbpoXc1Mtu4GpU6eZdOXFuuJK/IAgKluHDlMO1E= X-Google-Smtp-Source: ACHHUZ6lXSsYO2xx1zaxIWIh7xvSsrxnLKT9LqEhKEKBd9A1tQUvY/Wja49iDEzsSvvbquDAyLNgMeL7i4D5XwVwHdM= X-Received: by 2002:a05:6808:1a02:b0:39a:7830:f237 with SMTP id bk2-20020a0568081a0200b0039a7830f237mr1814937oib.7.1686447541295; Sat, 10 Jun 2023 18:39:01 -0700 (PDT) In-Reply-To: <83sfazzm8x.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263237 Archived-At: --000000000000a19f8805fdd0aa5d Content-Type: text/plain; charset="UTF-8" > Making the change in mm-url.el sounds scary: that code was written > many years ago, and who knows where it is used? Yeah, that makes sense. I'll see what I can find about that, at least within emacs itself. > The reason for testing bolp there is not explained, but I'm guessing > they didn't want to craete an empty line? Not sure. It looks like it was introduced during a patch intended to fix submitting binary data. Would it make sense to CC the two authors of the following commits? I dug into the history a bit to try to find out where =(unless (bolp)= came from #+begin_src bash git log -L '/(unless (bolp)/,+1:lisp/gnus/mm-url.el' > unless-bolp #+end_src It looks like it was introduced in this commit #+begin_quote commit fca2f70380dcb054497470aaf8eda6173063928e Author: Kenjiro Nakayama Date: Mon Nov 10 22:33:55 2014 +0100 Allow uploading files from eww #+end_quote and the "\r\n" was included unconditionally before the boundary #+begin_src elisp ;; use the boundary as a separator (concat "\r\n--" boundary "\r\n") #+end_src Then it this commit changed it #+begin_quote commit a6e0188dffc394698d9ffbef50401f14a31c8722 Author: Lars Ingebrigtsen Date: Thu Oct 13 21:39:29 2016 +0200 Fix problem with submitting binary data via HTTP forms #+end_quote to the following #+begin_src elisp (unless (bolp) (insert "\r\n")) #+end_src plus a bunch of "\r\n"s scattered throughout the different conditions. It's not clear to me how the behavior of the function changed. It looks like maybe instead of the initial diff I proposed, something like this would produce more accurate output for file uploads, and also change the surrounding code as little as possible, #+begin_quote diff --git a/lisp/gnus/mm-url.el b/lisp/gnus/mm-url.el index 11847a79f17..686dea20b6a 100644 --- a/lisp/gnus/mm-url.el +++ b/lisp/gnus/mm-url.el @@ -430,7 +430,8 @@ mm-url-encode-multipart-form-data (insert filedata)) ;; How can this possibly be useful? ((integerp filedata) - (insert (number-to-string filedata)))))) + (insert (number-to-string filedata))))) + (insert "\r\n")) ((equal name "submit") (insert "Content-Disposition: form-data; name=\"submit\"\r\n\r\nSubmit\r\n")) #+end_quote But it seems like it would be better to do a larger rewrite that consolidates the places where "\r\n" is added before the non-initial boundary. In order to figure that out, I will read the two versions more closely to figure out what the differences are and write some ERT tests showing the difference. Hopefully that will clear things up. --000000000000a19f8805fdd0aa5d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> Making the change in mm-url.el sound= s scary: that code was written
> many years ago, and who knows where = it is used?

Yeah, that makes sense. I'll see what I can find abo= ut that, at least
within emacs itself.

> The reason for testin= g bolp there is not explained, but I'm guessing
> they didn't= want to craete an empty line?

Not sure. It looks like it was introd= uced during a patch intended to fix
submitting binary data.=C2=A0 Would = it make sense to CC the two authors of the
following commits?

I d= ug into the history a bit to try to find out where =3D(unless (bolp)=3D
= came from

#+begin_src bash
git log -L '/(unless (bolp)/,+1:li= sp/gnus/mm-url.el' > unless-bolp
#+end_src

It looks like i= t was introduced in this commit

#+begin_quote
commit fca2f70380dc= b054497470aaf8eda6173063928e
Author: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
Date:= =C2=A0=C2=A0 Mon Nov 10 22:33:55 2014 +0100

=C2=A0=C2=A0=C2=A0 Allow= uploading files from eww
#+end_quote

and the "\r\n" wa= s included unconditionally before the boundary

#+begin_src elisp
= =C2=A0=C2=A0 ;; use the boundary as a separator
=C2=A0=C2=A0 (concat &qu= ot;\r\n--" boundary "\r\n")
#+end_src

Then it this= commit changed it

#+begin_quote
commit a6e0188dffc394698d9ffbef5= 0401f14a31c8722
Author: Lars Ingebrigtsen <larsi@gnus.org>
Date:=C2=A0=C2=A0 Thu Oct 13 21:39:29 201= 6 +0200

=C2=A0=C2=A0=C2=A0 Fix problem with submitting binary data v= ia HTTP forms
#+end_quote

to the following

#+begin_src eli= sp
=C2=A0(unless (bolp)
=C2=A0=C2=A0 =C2=A0=C2=A0 (insert "\r\n&= quot;))
#+end_src

plus a bunch of "\r\n"s scattered thr= oughout the different conditions.
It's not clear to me how the behav= ior of the function changed.

It looks like maybe instead of the init= ial diff I proposed, something
like this would produce more accurate out= put for file uploads, and also
change the surrounding code as little as = possible,

#+begin_quote
diff --git a/lisp/gnus/mm-url.el b/lisp/g= nus/mm-url.el
index 11847a79f17..686dea20b6a 100644
--- a/lisp/gnus/m= m-url.el
+++ b/lisp/gnus/mm-url.el
@@ -430,7 +430,8 @@ mm-url-encode-= multipart-form-data
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 (insert filedata))
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;; How can this possibly b= e useful?
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 ((integerp filedata)
-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (insert (number-to-string filedata))))= ))
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (insert (number-to-string filedata)))))
+=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (insert "\r\n"))
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((equal name "submit")
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (insert
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "Content-Disposition: fo= rm-data; name=3D\"submit\"\r\n\r\nSubmit\r\n"))
#+end_quo= te

But it seems like it would be better to do a larger rewrite that<= br>consolidates the places where "\r\n" is added before the non-i= nitial
boundary.

In order to figure that out, I will read the two= versions more closely
to figure out what the differences are and write = some ERT tests showing
the difference.=C2=A0 Hopefully that will clear t= hings up.

--000000000000a19f8805fdd0aa5d--