Fail a download whose chunk size is not a number

read_body took strtoull's answer for a chunk's size line, and 0, the
last chunk's size, is also what it answers for a line that is not a
number. A broken or cut response then ended as a complete download, cut
short (the update's zip then failed its check, or an update check's JSON
failed to parse). A size line without a hexadecimal number is now an
error.
This commit is contained in:
Milenko committed 2026-10-08 08:28:30 -04:00
1 parent 73dc01d09a
commit 2b89960b0a
1 file changed
+9 -1
+9 -1
View File
@@ -340,11 +340,19 @@ static int read_body(struct connection *connection, struct download *download, i
for (;;)
{
char line[128];
char *after;
unsigned long long remaining;
if (!connection_read_line(connection, line, sizeof(line)))
return 0;
remaining = strtoull(line, NULL, 16);
/* (a size in hexadecimal, perhaps with extensions after a ";": a
line without one is no chunk, and not the last) */
remaining = strtoull(line, &after, 16);
if (after == line || (*after && *after != ';' && *after != ' ' && *after != '\t' &&
*after != '\r' && *after != '\n'))
{
return 0;
}
if (!remaining)
return 1;
while (remaining)