Skip to content

fix(parser/hwpx): HwpUnitChar 값 2× 스케일 정수 오버플로 패닉 하드닝 — 손상 .hwpx DoS (#4839) - #4840

Closed
kevin9327 wants to merge 1 commit into
edwardkim:develfrom
kevin9327:gym_hwpx_dos_hardening
Closed

fix(parser/hwpx): HwpUnitChar 값 2× 스케일 정수 오버플로 패닉 하드닝 — 손상 .hwpx DoS (#4839)#4840
kevin9327 wants to merge 1 commit into
edwardkim:develfrom
kevin9327:gym_hwpx_dos_hardening

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

배경

close #4839

손상되거나 조작된 .hwpxContents/header.xml 에서 HwpUnitChar <hp:case> 안 극단 정수값이 "HwpUnitChar 1× → HWP5 2× IR 스케일" 변환(* 2)에서 정수 곱셈 오버플로 패닉을 일으킨다. parse_hwpx_header 가 그대로 죽으면서 info / export-text / export-structure / convert 전부가 손상 문서 한 건에 프로세스째 종료된다 (DoS, exit 101). 퍼징(원본 바이트 손상 + XML 파트 손상, 샘플 4종)으로 발견했다.

변경

src/parser/hwpx/header.rs 세 곳의 * 2saturating_mul(2) 로 교체한다. 셋 다 같은 스케일 변환이며 오버플로 가드가 없었다.

위치 대상 타입
1288 문단 여백 left/right/intent/prev/next i32
1357 문단 lineSpacing i32
1907 탭 position u32

정상 문서 값은 수천 HWPUNIT 수준이라 결과가 바뀌지 않고, 극단값만 i32::MAX / u32::MAX 로 포화되어 그레이스풀하게 처리된다. (같은 함수의 exact_value_from_default 는 이미 i64::from(...) 승격이라 안전하다 — 손대지 않음.)

재현 (수정 전)

정상 .hwpx<hh:paraPr> 에 HwpUnitChar <hp:case> + <hc:left value="2000000000"/> 주입 후:

$ rhwp info corrupt.hwpx
thread 'main' panicked at src\parser\hwpx\header.rs:1288:53:
attempt to multiply with overflow

exit 101. 호출 사슬: parse_para_shape_switchparse_para_shapeparse_hwpx_headerparse_hwpx.

검증

  • 재현 파일 → info / export-text / export-structure / convert 모두 exit 0, 패닉 없음.
  • 정상 샘플 3종(SO-SUEOP / hwp3-sample-hwpx / HWP5-nopassword-123456)의 info / export-text / export-structure 출력 바이트 동일(회귀 없음).
  • 회귀 테스트 hwpunitchar_oversized_value_saturates_without_panic 추가 (여백·줄간격·탭 세 경로 모두 포화 확인).
  • cargo test --lib 3703 passed / 0 failed.
  • rustfmt --edition 2021 --check src/parser/hwpx/header.rs 통과.

범위

HWPX 파서 전용(src/parser/hwpx/header.rs)에 한정한다. renderer vertical_pos+line_height, parser/mod.rs 오버플로(#4821), HWP5 body 재귀(#4830) 등 다른 DoS 는 별도 PR 이 다루므로 건드리지 않았다.

손상 .hwpx 의 header.xml HwpUnitChar <hp:case> 안 극단 정수값이 2× IR
스케일 변환(* 2)에서 곱셈 오버플로 패닉을 유발해 info/export-text/
export-structure/convert 전부가 손상 문서 한 건에 프로세스째 죽던 DoS 를
수정한다.

header.rs 세 곳의 * 2 를 saturating_mul(2) 로 교체:
- 1288: 문단 여백 left/right/intent/prev/next (i32)
- 1357: 문단 lineSpacing (i32)
- 1907: 탭 position (u32)

정상 문서 값은 수천 HWPUNIT 수준이라 무영향이고, 극단값만 i32::MAX/
u32::MAX 로 포화되어 그레이스풀하게 처리된다. 회귀 테스트 추가.
정상 샘플 3종 info/export-text/export-structure 출력 바이트 동일,
cargo test --lib 3703 passed/0 failed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@jangster77

Copy link
Copy Markdown
Collaborator

통합 PR #4883(4412546)로 병합 완료했습니다.

원 head와 CI를 다시 확인해 누적 반영했고, 상세 검토·메인터너 보정·검증 근거는 archive 검토 기록에 남겼습니다.

중복 병합을 막기 위해 이 원 PR을 닫습니다. 감사합니다.

@jangster77 jangster77 closed this Aug 15, 2026
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.

2 participants