Files
swift-nio/Sources
jmestwa-coderandCory Benfield 0b38af6217 fix off-by-one boundaries in QUIC bytesNeededForInteger (#3628)
Off-by-one in the QUIC variable-length integer length boundaries.

### Motivation:

`bytesNeededForInteger` classifies an integer into the 1/2/4/8 byte QUIC
encoding using half-open ranges (`0..<63`, `0..<16383`,
`0..<1_073_741_823`, `0..<4_611_686_018_427_387_903`). Those upper
bounds are the *largest* value each size can hold (2^6-1, 2^14-1, 2^30-1
and 2^62-1 per RFC 9000 § 16), so each maximum is wrongly excluded:

- 63, 16383 and 2^30-1 report one byte too many, so the encoder writes
them with a larger encoding than needed.
- 2^62-1, the largest value the encoding can represent, falls through to
the `fatalError` and crashes the encoder.

The existing one-byte write test only iterates `0..<63`, so the 63 case
was never exercised.

### Modifications:

- Switch the four ranges in `bytesNeededForInteger` to inclusive bounds.
- Extend the one-byte write test to include 63, and add boundary checks
plus a 2^62-1 round-trip test.

### Result:

Boundary values encode in the minimal number of bytes and 2^62-1
round-trips instead of crashing.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2026-06-22 12:45:20 +00:00
..
2024-09-12 13:18:25 +01:00
2025-10-06 10:58:33 +01:00
2025-05-07 12:24:44 +00:00
2025-05-07 12:24:44 +00:00