From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <t.lamprecht@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 194B3919C5
 for <pve-devel@lists.proxmox.com>; Thu, 29 Sep 2022 17:13:19 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id F029E6111
 for <pve-devel@lists.proxmox.com>; Thu, 29 Sep 2022 17:13:18 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Thu, 29 Sep 2022 17:13:17 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6463244659
 for <pve-devel@lists.proxmox.com>; Thu, 29 Sep 2022 17:13:17 +0200 (CEST)
Message-ID: <3ccc7309-1dee-118c-fec3-409bdbb90c8c@proxmox.com>
Date: Thu, 29 Sep 2022 17:13:16 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:106.0) Gecko/20100101
 Thunderbird/106.0
Content-Language: en-GB
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Matthias Heiserer <m.heiserer@proxmox.com>
References: <20220513134900.440420-1-m.heiserer@proxmox.com>
 <20220513134900.440420-2-m.heiserer@proxmox.com>
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
In-Reply-To: <20220513134900.440420-2-m.heiserer@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.029 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [anyevent.pm]
Subject: [pve-devel] applied: [PATCH v2 http-server 2/2] AnyEvent: Fix #3990
 - make small files uploadable
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 29 Sep 2022 15:13:19 -0000

Am 13/05/2022 um 15:49 schrieb Matthias Heiserer:
> == The problem
> Upload of files smaller than ~16kb failed.
> This was because the code assumed that it would be called
> several times, and each time would do a certain action.
> When the whole file was in the buffer, this failed because
> the function would try parssing the first part in the payload and
> then return, instead of parsing the rest of the available data.
> 
> == Why not just modifying the current code a bit?
> The code had a lot of nested control statements and a
> non-intuitive control flow (phase 0->2->1->1->1 and so on).
> 
> The way the phases and buffer content were checked made it
> rather difficult to just fix a few lines.
> 
> == What was changed
> * Part headers are parsed with a single regex line each,
>  which improves code readability.
> 
> * Parsing the content is done in order, so even if the whole data is in the buffer,
>  it can be read in one go. Files of arbitrary sizes can be uploaded.
> 
> == Tested with
> * Uploaded 0B, 1B, 14KB, 16KB, 1GB, 10GB, 20GB files
> 
> * Tested with all checksums and without
> 
> * Tested on firefox, chromium, and pvesh
> 
> I didn't do any fuzzing or automated upload testing.
> 
> == Drawbacks & Potential issues
> * Part headers are hardcoded, adding new ones requries modifying this file
> 
> == does not fix
> * upload can still time out
> 
> Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
> ---
> 
> Note:
> Regarding trim, I forgot to answer the mail.
> Trim is imo a good name, as several languagues (e.g. rust, javascript)
> use trim to mean mean "remove all whitespace, including newlines and such".
> I can send a v3 if that's a problem.
> 
> Changes from v1:
> * fix whitespace in separate patch
> * move trim into inline closure
> * correctly call trim
> * replace [^\S] with \S in regexes
> * improve trim regex: don't replace string
> * check for phase 1 once
> * remove regex comment
> 
>  src/PVE/APIServer/AnyEvent.pm | 146 ++++++++++++++++++----------------
>  1 file changed, 76 insertions(+), 70 deletions(-)
> 
>

applied, with slightly reworking the commit messages subject and Daniel's T-b tag,
thanks to both!

Note that I made some follow ups trying to improve a few things of your change and the
existing code. E.g.: $string in trim wasn't used anywhere, same for $eof in phase 2.
The content-disposition extraction could be factored in a small closure to reduce code
size and (IMO) legibility, and some other smaller style/formatting stuff.

None of that was a blocker, and due to the age of this series (sorry for that!) I
really did not want to bother for a v3 and applied changes myself. I re-tested it
with various sizes and functionality (checksum), but an additional pair of eyes
would be appreciated to ensure no regression snuck in.