Fix calculation of overlap_simple_bit_stream_size#8
Open
jermy wants to merge 1 commit intoCimpress-MCP:mainfrom
Open
Fix calculation of overlap_simple_bit_stream_size#8jermy wants to merge 1 commit intoCimpress-MCP:mainfrom
jermy wants to merge 1 commit intoCimpress-MCP:mainfrom
Conversation
This fixes the "Stream truncated" error seen with a number of woff2 fonts. Currently the calculation of overlap_simple_bit_stream_size uses the same function as for bitmap_stream_length but in the specification the latter should be rounded up to the next 32bit boundary, and the former should be only to the next byte boundary. This simplifies/removes the bit_stream_byte_length function and uses the same inline calculation for this as the the woff2 reference decoder.
virtualritz
added a commit
to virtualritz/woff2-rs2
that referenced
this pull request
Oct 24, 2025
This commit addresses multiple robustness and maintainability issues. Error Handling Improvements: - Preserve full error chain in DecodeError instead of flattening to strings. - Add typed error variants (InvalidHeader, InvalidCollectionHeader, etc.). - Replace unwrap() with try_from() for safe size conversions. - Add SizeOverflow error for conversion failures. - Add OffsetOverflow error for table offset calculations. Performance Improvements: - Fix O(n²) complexity in Woff2TableDirectory::write_to_buf. - Use indexed iteration instead of iterator cloning. Safety & Validation: - Add overflow checks in Woff2TableDirectory::from_buf using checked_add. - Fix TableDirectory::new to handle zero tables gracefully with assertion. - Enforce WOFF2 spec requirement: loca must immediately follow glyf in collections. - Add LocaNotAdjacentToGlyf error for spec violations. API Naming (Rust API Guidelines): - Remove get_ prefix from getters: get_four_cc → four_cc. - Rename try_get_four_cc → try_four_cc. - Rename try_get_base_128 → try_base_128. - Rename try_get_255_u16 → try_255_u16. - Rename get_source_range → source_range. - Rename get_range → range. Merged Upstream PRs: - PR #8: Fix calculation of overlap_simple_bit_stream_size. Cimpress-MCP/woff2-rs#8 - PR #9: Fix error conversion issues for modern Rust compatibility. Cimpress-MCP/woff2-rs#9 - PR #6: Fix header compressed size check with alignment. Cimpress-MCP/woff2-rs#6 Documentation: - Fix doctest to use correct crate name (woff2_patched). - Update TableDirectory::new documentation with panic conditions. - Clarify glyf/loca adjacency requirements in comments. All tests passing (11 unit tests + 1 doctest).
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.
This fixes the "Stream truncated" error seen with a number of woff2 fonts. Currently the calculation of overlap_simple_bit_stream_size uses the same function as for bitmap_stream_length but in the specification the latter should be rounded up to the next 32bit boundary, and the former should be only to the next byte boundary.
This simplifies/removes the bit_stream_byte_length function and uses the same inline calculation for this as the the woff2 reference decoder.
I know there's not much activity in this repository, but leaving this here if anybody else hits this issue.