curl/tests/http
Keng-Yu Lin 703a999602
tests: fix type promotion on 32-bit arches in http test code
As reported in the bug:

> On a 32-bit architecture (i386):
> 1. `chunks * chunk_size` evaluates to `unsigned int` (32-bit
>    unsigned).
> 2. Due to Usual Arithmetic Conversions in C, the signed `-1` (int)
>    operand of the ternary operator is promoted to `unsigned int`,
>    yielding `4294967295` (0xFFFFFFFF).
> 3. The ternary operator returns `4294967295` as an `unsigned int`.
> 4. This unsigned value is then assigned to `r->clength` (apr_off_t,
>    64-bit signed). Since the source is unsigned, it is zero-extended,
>    resulting in `r->clength` becoming `+4294967295`.
> 5. The subsequently executed check `if(r->clength >= 0)` evaluates to
>    true.
> 6. Inside the block, `apr_ltoa(r->pool, (long)r->clength)` casts it to
>    a 32-bit signed `long` (on 32-bit platforms), which truncates it
>    back to `-1`, formatting it as "-1" and sending the
>    "Content-Length: -1" header.
>
> On a 64-bit architecture (amd64), `size_t` is 64-bit, and `-1` (32-bit
> int) is promoted to `unsigned long` (64-bit), yielding
> `18446744073709551615`. When assigned to `r->clength` (64-bit signed),
> it wraps back to `-1`, which correctly skips the Content-Length
> generation.
>
> This type promotion mismatch can be safely fixed by avoiding the
> signed/unsigned mixture in the ternary operator.

Origin: debian, https://bugs.debian.org/1140793
Bug-Debian: https://bugs.debian.org/1140793

These are standard Debian patches' trailers, I can get rid of then if you prefer.

I've tested the fix using [debusine on i386 runner](https://debusine.debian.net/debian/developers/artifact/4083252/raw/log):

> 782s tests/http/test_05_errors.py::TestErrors::test_05_04_unclean_tls_shutdown[http/1.0] PASSED [ 17%]
> 782s tests/http/test_05_errors.py::TestErrors::test_05_04_unclean_tls_shutdown[http/1.1] PASSED [ 18%]
> 782s tests/http/test_05_errors.py::TestErrors::test_05_04_unclean_tls_shutdown[h2] PASSED [ 18%]

Versus the [i386 run in Debian's infrastructure](https://debusine.debian.net/debian/developers/artifact/4084220/raw/log):

> 2690s tests/http/test_05_errors.py::TestErrors::test_05_04_unclean_tls_shutdown[http/1.0] FAILED [ 17%]
> 2690s tests/http/test_05_errors.py::TestErrors::test_05_04_unclean_tls_shutdown[http/1.1] PASSED [ 18%]
> 2690s tests/http/test_05_errors.py::TestErrors::test_05_04_unclean_tls_shutdown[h2] PASSED [ 18%]

Closes #22210
2026-07-20 19:13:53 +02:00
..
testenv tests: fix type promotion on 32-bit arches in http test code 2026-07-20 19:13:53 +02:00
.gitignore tidy-up: mostly whitespace nits 2023-08-31 23:02:10 +00:00
CMakeLists.txt HTTP/3: add proxy CONNECT and MASQUE CONNECT-UDP support (ngtcp2 QUIC) 2026-05-27 08:49:53 +02:00
config.ini.in HTTP/3: add proxy CONNECT and MASQUE CONNECT-UDP support (ngtcp2 QUIC) 2026-05-27 08:49:53 +02:00
conftest.py FTP: fix TLS session reuse on the data connection 2026-07-02 17:39:04 +02:00
Makefile.am ws: pause/unpause write handling 2026-07-12 18:06:21 +02:00
requirements.txt GHA: bump pip cryptography from 46.0.7 to 48.0.1 2026-06-16 22:18:43 +02:00
scorecard.py lib: ratelimit timestamps 2026-07-13 11:53:00 +02:00
test_01_basic.py tests: alphabetize and group Python imports & add check 2026-04-08 10:28:05 -07:00
test_02_download.py conncache: apply multi limits to transfers using a shared pool 2026-07-12 15:08:31 -04:00
test_03_goaway.py tests: alphabetize and group Python imports & add check 2026-04-08 10:28:05 -07:00
test_04_stuttered.py tests: alphabetize and group Python imports & add check 2026-04-08 10:28:05 -07:00
test_05_errors.py tidy-up: miscellaneous 2026-06-09 11:07:55 +02:00
test_06_eyeballs.py tidy-up: typos, comment nits 2026-07-11 13:55:45 +02:00
test_07_upload.py pytest: close file handles after use, and two minor tidy-ups 2026-06-09 02:05:21 +02:00
test_08_caddy.py pytest: close file handles after use, and two minor tidy-ups 2026-06-09 02:05:21 +02:00
test_09_push.py tidy-up: add space around operators, where missing 2026-05-28 10:12:00 +02:00
test_10_proxy.py tidy-up: typos, comment nits 2026-07-11 13:55:45 +02:00
test_11_unix.py unix-sockets: ignore proxy settings 2026-05-16 18:49:46 +02:00
test_12_reuse.py tests: pin connection reuse rules for partial, host, and credentials 2026-06-30 09:57:00 +02:00
test_13_proxy_auth.py pytest: close file handles after use, and two minor tidy-ups 2026-06-09 02:05:21 +02:00
test_14_auth.py tidy-up: miscellaneous 2026-06-01 22:33:57 +02:00
test_15_tracing.py tests: alphabetize and group Python imports & add check 2026-04-08 10:28:05 -07:00
test_16_info.py tidy-up: add space around operators, where missing 2026-05-28 10:12:00 +02:00
test_17_ssl_use.py pytest: close file handles after use, and two minor tidy-ups 2026-06-09 02:05:21 +02:00
test_18_methods.py tidy-up: add space around operators, where missing 2026-05-28 10:12:00 +02:00
test_19_shutdown.py cfilters: fix event-based connection shutdown 2026-07-17 04:00:56 -04:00
test_20_websockets.py ws: pause/unpause write handling 2026-07-12 18:06:21 +02:00
test_21_resolve.py hostip: only cache negative resolves for authoritative answers 2026-07-13 11:27:16 +02:00
test_22_httpsrr.py pythonlint.sh: make it fail on error, fix ruff warnings in pytest 2026-05-13 22:59:36 +02:00
test_30_vsftpd.py pytest: close file handles after use, and two minor tidy-ups 2026-06-09 02:05:21 +02:00
test_31_vsftpds.py FTP: fix TLS session reuse on the data connection 2026-07-02 17:39:04 +02:00
test_32_ftps_vsftpd.py FTP: fix TLS session reuse on the data connection 2026-07-02 17:39:04 +02:00
test_40_socks.py lib: transfer origin and proxy handling 2026-06-12 23:52:00 +02:00
test_50_scp.py pytest: close file handles after use, and two minor tidy-ups 2026-06-09 02:05:21 +02:00
test_51_sftp.py pytest: close file handles after use, and two minor tidy-ups 2026-06-09 02:05:21 +02:00
test_60_h3_proxy.py tidy-up: typos, comment nits 2026-07-11 13:55:45 +02:00