-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Reading gzip headers can lead to OOM for adversarial inputs #149945
Copy link
Copy link
Open
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Metadata
Metadata
Assignees
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
In short
_read_until_null(added a few days ago in dd94457), appends every byte from a stream into abytearraywith no upper bound (here). Any gzip stream that setsFNAMEorFCOMMENTtogether with any other flag (bypassing the early-exit at theflag == FNAMEfast-path) and never emits a NUL byte will cause theheaderbytearray to grow until memory is exhausted. This occurs before any decompression takes place, so existing mitigations for zip-bomb-like inputs that bound decompressed output size do not apply.Proposed fix
Cap
_read_until_nullat a reasonable per-field limit and raiseBadGzipFileif exceeded:(65535 bytes was picked to match the maximum
FEXTRAfield size (a 16-bit length prefix), making all variable-length header fields consistent.)I have a branch that adds a mitigation here in my fork.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs