Bound emitter output growth before allocation#14
Merged
Conversation
The emitter previously enforced max_output_bytes only after building the complete output buffer. That meant callers could still hit allocator growth, or writer APIs could allocate the full output, before the configured safety limit returned error.Unsupported. Add an internal OutputBuffer wrapper that checks the configured output byte budget before every append. The existing block, flow, scalar, and tag emitter helpers now accept the checked output buffer shape, while their unit tests can still pass ordinary ArrayList buffers. When the checked buffer trips the budget, emit maps that internal allocation-shaped failure back to ParseError.Unsupported. Add a regression using a FixedBufferAllocator and an oversized scalar so the test fails with OutOfMemory on the old behavior and passes only when the output limit is checked before buffer growth. Also align the default coverage threshold with CI by changing plain zig build coverage to default to 85 percent instead of 100 percent, and extend the structure test to keep build.zig and CI in sync. Verification run: zig fmt --check build.zig build.zig.zon src tests tools; zig build test; zig build coverage; zig build test-stress; zig build test-allocation; zig build test-leaks; zig build conformance-report.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The emitter previously enforced max_output_bytes only after building the complete output buffer. That meant callers could still hit allocator growth, or writer APIs could allocate the full output, before the configured safety limit returned error.Unsupported.
Add an internal OutputBuffer wrapper that checks the configured output byte budget before every append. The existing block, flow, scalar, and tag emitter helpers now accept the checked output buffer shape, while their unit tests can still pass ordinary ArrayList buffers. When the checked buffer trips the budget, emit maps that internal allocation-shaped failure back to ParseError.Unsupported.
Add a regression using a FixedBufferAllocator and an oversized scalar so the test fails with OutOfMemory on the old behavior and passes only when the output limit is checked before buffer growth.
Also align the default coverage threshold with CI by changing plain zig build coverage to default to 85 percent instead of 100 percent, and extend the structure test to keep build.zig and CI in sync.
Verification run: zig fmt --check build.zig build.zig.zon src tests tools; zig build test; zig build coverage; zig build test-stress; zig build test-allocation; zig build test-leaks; zig build conformance-report.