Skip to content

fix: add depth limits to prevent stack overflow on deeply nested tables#98

Merged
developer0hye merged 1 commit intomainfrom
ralph/phase21-fix-stack-overflow
Mar 1, 2026
Merged

fix: add depth limits to prevent stack overflow on deeply nested tables#98
developer0hye merged 1 commit intomainfrom
ralph/phase21-fix-stack-overflow

Conversation

@developer0hye
Copy link
Owner

Summary

  • Adds MAX_TABLE_DEPTH (64) constant to both the DOCX parser and Typst renderer to prevent stack overflow on pathological documents with thousands of nested tables
  • Parser side (docx.rs): threads a depth parameter through convert_table()extract_raw_rows()extract_cell_content(); silently truncates nesting beyond the limit
  • Renderer side (typst_gen.rs): adds table_depth field to GenCtx; generate_table() increments/decrements depth, generate_cell_content() skips nested tables at the limit

Related: #94

Test plan

  • cargo test -p office2pdf --test docx_fixtures smoke_deep_table_cell passes (no stack overflow)
  • cargo test --workspace — all tests pass
  • cargo fmt --all -- --check — clean
  • cargo clippy --workspace -- -D warnings — clean
  • Bulk conversion: 2792 files, 0 panics, 99.6% success rate

🤖 Generated with Claude Code

Add MAX_TABLE_DEPTH (64) constant to both the DOCX parser and Typst
renderer. Deeply nested tables beyond this limit are silently truncated
instead of causing a stack overflow.

Parser (docx.rs):
- convert_table(), extract_raw_rows(), extract_cell_content() now accept
  a depth parameter; top-level callers pass 0
- extract_cell_content() skips nested tables when depth >= MAX_TABLE_DEPTH

Renderer (typst_gen.rs):
- GenCtx gains a table_depth field (default 0)
- generate_table() increments/decrements depth via a wrapper
- generate_cell_content() skips Block::Table when depth >= MAX_TABLE_DEPTH

Fixes #94

Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
@developer0hye developer0hye merged commit 4bbf754 into main Mar 1, 2026
13 of 14 checks passed
@developer0hye developer0hye deleted the ralph/phase21-fix-stack-overflow branch March 1, 2026 16:50
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