Skip to content

fix(varint): reject 10-byte terminator overflow and align error types - #1462

Merged
acul71 merged 1 commit into
mainfrom
harden/varint-uvarint-overflow-1458
Aug 30, 2026
Merged

fix(varint): reject 10-byte terminator overflow and align error types#1462
acul71 merged 1 commit into
mainfrom
harden/varint-uvarint-overflow-1458

Conversation

@acul71

@acul71 acul71 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1458

What was wrong?

A 10-byte uvarint encoding whose terminating byte still carries extra payload bits could decode to a value greater than 2^64-1 (e.g. decode_uvarint(b"\xff" * 9 + b"\x7f")). Over-long buffer-path failures also raised ValueError while the stream decoder raised ParseError, so callers catching only one type handled the two malformation classes inconsistently.

How was it fixed?

  • Added a shared _reject_uvarint_overflow guard used by decode_uvarint and decode_uvarint_from_stream before returning a decoded value.
  • Unified over-long buffer-path failures to ParseError with the same message as the stream decoder.
  • Expanded docstrings for decode_uvarint_from_stream and decode_varint_with_size (truncation/partial-return contract documented; behavior of decode_varint_with_size unchanged for WebRTC except ValueError guards).
  • Added rejection tests for 11-byte encodings and 10-byte terminator overflow on both buffer and stream paths.

Test plan

  • pytest tests/core/utils/test_varint.py tests/core/utils/test_varint_message_limits.py
  • make lint
  • make typecheck
  • make test
  • make linux-docs

Cute Animal Picture

European otter

Harden decode_uvarint and decode_uvarint_from_stream against encodings
whose terminating byte overflows 64 bits, and raise ParseError consistently
for over-long buffer-path failures. Document decode_varint_with_size's
truncation contract without changing its behavior.

Fixes #1458

Co-authored-by: Cursor <cursoragent@cursor.com>
@acul71
acul71 merged commit 20d9527 into main Aug 30, 2026
38 checks passed
@acul71
acul71 deleted the harden/varint-uvarint-overflow-1458 branch August 30, 2026 00:10
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.

varint: reject 10-byte last-byte overflow and align decoder error types

1 participant