[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] wget-1.21: Issue with file downloads via HTTP with size >= than

From: Luis Alberto Dallos Roa
Subject: [PATCH] wget-1.21: Issue with file downloads via HTTP with size >= than 2 GiB on 32-bit platforms
Date: Mon, 11 Jan 2021 09:51:01 -0400

There is an issue in wget 1.21 series regarding file downloads via
HTTP with size greater or equal than 2 GiB (2147483648 Bytes) on
platforms where "long" data type is 32-bit such as 32-bit *nix and M$
Windows (both 32-bit and 64-bit). On those platforms, when downloading
via HTTP a file with size greater or equal than 2 GiB, wget downloads
only the first 2^31 - 1 (i.e. 2147483647) Bytes. Only downloads from
the beginning are affected, resuming a partially downloaded file is
not affected.

In detail, this issue occurs due to using the str_to_wgint macro
(which is unconditionally defined as strtol at line 147 of src/wget.h)
to convert a "Content-Length" header value greater than 2^31 - 1 Bytes
(see line 3504 at src/http.c). The strtol(3) call fails with errno set
to ERANGE but returns LONG_MAX (0x7FFFFFFFUL), so neither the
out-of-range Content-Length (line 3505 at src/http.c) nor the negative
Content-Length (line 3514 at src/http.c) conditions are met, and this
leads to wget assuming that the file has a size of 2^31 - 1 Bytes
(line 3521 at src/http.c).

Debug log (Content-Length incorrectly decoded): https://pastebin.com/P6sDnvzk

Debug log (Content-Length correctly decoded):   https://pastebin.com/2KfFzACn

Below is a patch which fixes this issue by defining the str_to_wgint
macro in accordance with the size of the "long" data type (SIZEOF_LONG

From: Luis Dallos <luis.dallos@googlemail.com>

diff --git a/src/wget.h b/src/wget.h
index b6a9dca..7fd6359 100644
--- a/src/wget.h
+++ b/src/wget.h
@@ -144,7 +144,11 @@ typedef int64_t wgint;
 #define WGINT_MAX INT64_MAX
 typedef wgint SUM_SIZE_INT;

-#define str_to_wgint strtol
+#if SIZEOF_LONG >= 8
+# define str_to_wgint strtol
+# define str_to_wgint strtoll

 #include "options.h"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]