Skip to content

fix: compute padding correctly for MAX_LENGTH (0xffff) content#35

Merged
jmjoy merged 1 commit intojmjoy:masterfrom
iadev09:fix-padding-overflow
Apr 15, 2026
Merged

fix: compute padding correctly for MAX_LENGTH (0xffff) content#35
jmjoy merged 1 commit intojmjoy:masterfrom
iadev09:fix-padding-overflow

Conversation

@iadev09
Copy link
Copy Markdown
Contributor

@iadev09 iadev09 commented Apr 14, 2026

The previous padding calculation used signed negation via i16, which could overflow for large content lengths. Switch to wrapping unsigned arithmetic so padding is computed correctly across the full u16 range, including 0xffff (MAX_LENGTH)

This can be reproduced in debug builds with large content lengths, resulting in:

attempt to negate with overflow
/fastcgi-client-0.11.0/src/meta.rs:168:30
stack backtrace:
0: __rustc::rust_begin_unwind

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes FastCGI Header padding computation for large content_length values by avoiding signed negation overflow and using wrapping unsigned arithmetic, ensuring correct padding across the full u16 range up to MAX_LENGTH (0xffff).

Changes:

  • Replace i16-based negation with u16::wrapping_sub to compute padding_length safely for all content_length values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jmjoy jmjoy merged commit aa9b97d into jmjoy:master Apr 15, 2026
10 checks passed
@iadev09 iadev09 deleted the fix-padding-overflow branch April 15, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants