Skip to content

Bound emitter output growth before allocation#14

Merged
ncode merged 1 commit into
mainfrom
juliano/bound-emitter-output
Jun 21, 2026
Merged

Bound emitter output growth before allocation#14
ncode merged 1 commit into
mainfrom
juliano/bound-emitter-output

Conversation

@ncode

@ncode ncode commented Jun 21, 2026

Copy link
Copy Markdown
Owner

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.

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.
@ncode ncode merged commit 87fc700 into main Jun 21, 2026
1 check 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