model/page: 페이지 영역 여백 산술 오버플로 하드닝 — batch 퍼징 실측 DoS (#4833) - #4834
Closed
kevin9327 wants to merge 1 commit into
Closed
model/page: 페이지 영역 여백 산술 오버플로 하드닝 — batch 퍼징 실측 DoS (#4833)#4834kevin9327 wants to merge 1 commit into
kevin9327 wants to merge 1 commit into
Conversation
손상 hwp3 문서에서 margin_footer > page_height 이면 PageAreas:: from_page_def_for_page 의 footer 아래 경계 `page_height - margin_footer` 가 u32 언더플로해 패닉했다. 단건 `rhwp info` 는 catch_unwind 가드가 없어 손상 파일 한 개로 exit 101 크래시(DoS), batch 는 격리하지만 정상 문서를 실패로 보고했다. 같은 함수가 이미 대부분 saturating_* 를 쓰는 규약대로 남은 세 자리를 맞춘다: footer 뺄셈은 saturating_sub, margin_header+margin_top·margin_left+margin_gutter 덧셈은 saturating_add. 정상 문서에서는 결과가 동일하고, 극값만 포화 후 기존의 본문 소멸 폴백이 흡수한다. - 단위 테스트: model::page::test_page_areas_extreme_margins_do_not_overflow - 통합 테스트: batch_axes_contract::batch_isolates_corrupt_page_def_without_panic - edwardkim#4818(렌더러)·edwardkim#4821(파서)과 다른 파일·다른 자리 (중복 아님) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
Author
|
중복 정리: 이 PR의 |
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.
무엇을
batch경로 퍼징이 드러낸src/model/page.rs의 페이지 영역 여백 산술 오버플로패닉(DoS)을 잠근다. 손상 hwp3 문서에서
margin_footer > page_height이면page_height - margin_footer뺄셈이 u32 언더플로해 패닉했다.Fixes #4833
왜
rhwp info <file>)에는catch_unwind가드가 없어, 손상 파일 한 개로프로세스가 exit 101 로 크래시한다(DoS). 재현:
samples/hwp3-pagedef-1915.hwp의헤더 2바이트(offset 51→0x5d, 56→0xd1)만 뒤집으면
panicked at src\model\page.rs:271:21: attempt to subtract with overflow.batch는 행별catch_unwind로 격리하므로 프로세스는 죽지 않지만, 정상 처리가능한 문서가 "내부 오류(panic)" error 레코드로 잘못 보고된다.
어떻게
PageAreas::from_page_def_for_page는 이미 대부분의 여백 산술을saturating_*로처리한다(예:
content_right,content_bottom). 빠져 있던 세 자리를 같은 규약으로맞춘다:
page_height - margin_footer→saturating_submargin_header + margin_top→saturating_addmargin_left + margin_gutter→saturating_add(양쪽 제본 분기 모두)정상 문서(
margin_footer <= page_height, 여백 합이 u32 이내)에서는 결과가 동일하다. 극값에서만 포화되고, 기존의 "본문 소멸 시 용지 5% 기본 여백" 폴백이 이를
정상 경로로 흡수한다.
중복 아님
src/renderer/*i32 오버플로)·PR 파서 normalize_variant_paragraph_vpos i32 오버플로 패닉 수정 — 퍼징 실측 DoS (#4820) #4821(파서src/parser/mod.rs오버플로)과 다른 파일·다른 자리다.
batch러너 자체(스레딩·NDJSON 스트리밍·집계·행별 격리)는 퍼징에서 크래시·교착이없었다. 4만 경로 목록도 선형 처리량(약 1,600 files/s)으로 완주했고, 손상 파일은
catch_unwind로 격리된다. 이 PR 은 batch 퍼징이 드러낸 별개의 단일 결함만 고친다.검증
rhwp info corrupt.hwp→ exit 101 패닉. 수정 후 → 정상 봉투, exit 0.src/model/page.rs::test_page_areas_extreme_margins_do_not_overflow:margin_footer = u32::MAX(뺄셈)·margin_header/top/left/gutter = u32::MAX(덧셈,단면/양면 제본 모두) 에서 패닉 없이 양수 본문 영역으로 폴백. (수정 전엔 패닉으로 실패)
tests/batch_axes_contract.rs::batch_isolates_corrupt_page_def_without_panic:[유효·손상(page.rs 트리거)·쓰레기·유효] 배치가 패닉 없이 완주하고, 입력 N=출력 N,
순서 보존, 진짜 실패 행(쓰레기)만 격리해 exit 1, 손상 페이지 정의 행은 성공 레코드.
cargo test --lib회귀 없음.rustfmt --edition 2021 --check통과(변경 두 파일).