Skip to content

Refuse to compress an input the stream format cannot express - #257

Merged
danilak-G merged 1 commit into
google:mainfrom
lenamonj:refuse-oversized-input
Sep 7, 2026
Merged

Refuse to compress an input the stream format cannot express#257
danilak-G merged 1 commit into
google:mainfrom
lenamonj:refuse-oversized-input

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

InternalCompress guarded the 2^32-byte limit with an assert only, so every NDEBUG build compressed a larger input into a stream whose length varint held N mod 2^32 while the body carried all N bytes: a 4 GiB input produced a header claiming 0 bytes.

The guard is now a runtime check at the one funnel every compression entry point passes through. An input of 2^32 bytes or more writes nothing and returns zero bytes written, which no successful compression can return; snappy_compress returns SNAPPY_INVALID_INPUT. The headers document the limit. The new test drives a 4 GiB Source without materialising it and fails on main (201457665 bytes written).

@google-cla

google-cla Bot commented Sep 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@lenamonj

lenamonj commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

@lenamonj
lenamonj force-pushed the refuse-oversized-input branch from a6bba59 to 29ecfbb Compare September 6, 2026 09:06
InternalCompress checked the 2^32-byte limit with an assert only, so
every NDEBUG build compressed a larger input into a stream whose length
varint held N mod 2^32 while the body carried all N bytes. The check is
now a runtime refusal at the single funnel every compression entry point
uses: nothing is written and zero is returned, which no successful
compression can return; snappy_compress returns SNAPPY_INVALID_INPUT.
The headers document the limit and a test drives a 4 GiB Source without
materialising it.
@lenamonj
lenamonj force-pushed the refuse-oversized-input branch from 29ecfbb to 1a09131 Compare September 6, 2026 09:15
@danilak-G
danilak-G merged commit 5a11aa3 into google:main Sep 7, 2026
29 checks passed
@lenamonj
lenamonj deleted the refuse-oversized-input branch September 7, 2026 09:57
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.

2 participants