Repository navigation
fix: avoid panic in layout when a section has no page definition - #9
Merged
Indosaram merged 1 commit intoSep 6, 2026
Merged
Conversation
LayoutEngine::calculate_layout panicked via expect("Section must have
page definition") for any parsed document whose section lacks a PageDef
record. PageDef is optional in the body-text stream and Section::page_def
defaults to None, so a valid HWP file without that record (e.g. the
repo's own styled_document.hwp) crashed callers of the public layout API.
Skip sections without a page definition instead of unwrapping.
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.
Problem
LayoutEngine::calculate_layout()panics on a parsed document whose section has noPageDefrecord:layout_sectionunwrapssection.page_defwith.expect("Section must have page definition"). But a page definition is optional in the body-text stream —PageDefis only set for thePageDef(0x57) record, andSection::page_defdefaults toNone. Any valid HWP file that doesn't carry that record crashes every caller of the public layout API.This is reproducible with the repository's own sample file
styled_document.hwp, which parses cleanly but has no page definition:(
converted_output.hwp, which does carry aPageDef, lays out fine — 2 pages.)Fix
Skip a section that has no page definition instead of unwrapping, so layout returns whatever it can rather than aborting the process.
Tests
tests/layout_missing_page_def_test.rsloads the shippedstyled_document.hwp, asserts a section has nopage_def, and checkscalculate_layout()returns without panicking.cargo test --all-features— 150 tests pass, 0 failures.Validation commands: