tests: fix type promotion on 32-bit arches in http test code - #22210
Closed
charles2910 wants to merge 1 commit into
Closed
tests: fix type promotion on 32-bit arches in http test code#22210charles2910 wants to merge 1 commit into
charles2910 wants to merge 1 commit into
Conversation
vszakats
reviewed
Jun 29, 2026
icing
approved these changes
Jul 7, 2026
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 Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
charles2910
force-pushed
the
fix-type-promotion-on-32-bit-arch
branch
from
July 7, 2026 16:51
f44dad1 to
4323f46
Compare
vszakats
approved these changes
Jul 20, 2026
Member
There was a problem hiding this comment.
Tested the type bump method (#22210 (comment)), but it's no good, chunk_size is better kept as size_t.
(Ref: #22359 (comment))
Member
|
Thanks Charles, merged now! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As reported in the bug:
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:
Versus the i386 run in Debian's infrastructure: