Skip to content

Use gzip trailer unpacked size as initial buffer capacity (fixes #7) - #29

Merged
mahach666 merged 2 commits into
mainfrom
fix/issue-7-gzip-initial-capacity
Nov 14, 2026
Merged

mahach666 merged 2 commits into
mainfrom
fix/issue-7-gzip-initial-capacity

Conversation

@mahach666

Copy link
Copy Markdown
Contributor

Allocate the output buffer with initial capacity matching the gzip trailer's declared unpacked size (size, already capped by maxUnpacked), avoiding repeated Array.Resize doubling and eliminating 2x peak memory allocation while preserving CRC and length validation.

@mahach666 mahach666 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not merge yet: the allocation change trusts the gzip trailer before validating the compressed data. The issue below was reproduced with a synthetic input; the same allocation check passes on main.

Comment thread src/TdbIO/Internal/Gzip.cs Resolved
Bound initial buffer size and grow as bytes are inflated to prevent forged ISIZE from allocating large buffers on invalid data. Add regression test.
@mahach666
mahach666 merged commit c422fa4 into main Nov 14, 2026
2 checks passed
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.

1 participant