mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
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>