fix(serializer): OLE Storage BinData 4-byte size prefix 복원#954
Closed
civilian7 wants to merge 1 commit into
Closed
fix(serializer): OLE Storage BinData 4-byte size prefix 복원#954civilian7 wants to merge 1 commit into
civilian7 wants to merge 1 commit into
Conversation
HWP 의 OLE 임베디드 개체 BinData 스트림은 `[4-byte LE size][CFB 컨테이너]` 형식이다. 파서(`load_bin_data_content`)는 내부 CFB 를 바로 노출하려고 이 prefix 를 제거(`drain(..4)`)하지만, 직렬화기(`cfb_writer`)가 이를 복원하지 않아 round-trip 시 prefix 가 누락됐다. 그 결과 한컴 오피스가 재저장된 문서의 OLE 개체를 열 때 CFB 매직(D0CF11E0)을 개체 크기(~3.75GB)로 오인하여 "메모리 부족" 오류로 문서 열기에 실패했다. `write_hwp_cfb` 의 BinData 직렬화에서 OLE Storage 타입이면 파서의 strip 조건을 그대로 미러링하여 4-byte LE size prefix 를 복원한다. 회귀 테스트 `test_ole_storage_size_prefix_restored` 추가.
edwardkim
pushed a commit
that referenced
this pull request
May 17, 2026
…ck PR #954) 파서(load_bin_data_content)가 내부 CFB 노출을 위해 제거한 [4-byte LE size] prefix 를 직렬화 시 복원. 미복원 시 한컴이 CFB 매직(D0CF11E0)을 OLE 개체 크기(~3.75GB)로 오인 → "메모리 부족" 오류로 문서 열기 실패. 회귀 테스트 test_ole_storage_size_prefix_restored 추가. Original-Author: civilian7 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
edwardkim
pushed a commit
that referenced
this pull request
May 17, 2026
Owner
|
rhwp에 보내주신 첫 PR 진심으로 환영하고 감사드립니다! 🎉 OLE 임베디드 개체 round-trip 시 한컴 "메모리 부족" 오류의 원인을 정확히 짚어주셨습니다. 파서의 검증 완료:
cherry-pick으로 devel에 반영했습니다 (원작자 표기 보존). 앞으로의 기여도 기대하겠습니다. 감사합니다! |
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.
문제
OLE 임베디드 개체를 포함한 HWP 문서를 rhwp 로 파싱한 뒤 다시 직렬화(
serialize_hwp)하면, 결과 파일을 한컴 오피스에서 열 때 "메모리 부족" 오류가 발생하며 문서가 열리지 않습니다. (rhwp 자체 파서로는 정상 재열림)원인
HWP 의 OLE Storage BinData 스트림은
[4-byte LE size][CFB 컨테이너]형식입니다.load_bin_data_content는 내부 CFB(D0CF11E0…)를 바로 노출하기 위해 이 4-byte size prefix 를 제거합니다 (decompressed.drain(..4), Task 차트/OLE 개체 렌더링 지원 #195).cfb_writer::write_hwp_cfb는 BinData 를 그대로 다시 쓰며 prefix 를 복원하지 않습니다.→ 재저장된 파일의 OLE BinData 는 prefix 없이 곧바로 CFB 매직으로 시작합니다. 한컴은 첫 4바이트
D0 CF 11 E0를 OLE 개체 크기로 해석 → LE0xE011CFD0≈ 3.75 GB 할당 시도 → "메모리 부족".실제 문서 비교에서, 재직렬화 파일의 모든 CFB 스트림(DocInfo · BodyText · 이미지 BinData 등)은 원본과 바이트 단위로 동일했고 OLE BinData 만 정확히 4바이트 짧았습니다.
수정
write_hwp_cfb의 BinData 직렬화 루프에서, BinData 가 OLE Storage 타입이고 내용이 CFB 매직으로 시작하면 4-byte LE size prefix 를 복원합니다. 파서의 strip 조건(is_storage && data[..8] != magic && data[4..12] == magic)을 그대로 미러링하므로, prefix 가 없던 입력에는 영향을 주지 않습니다.검증
test_ole_storage_size_prefix_restored추가cargo test serializer::cfb_writer— 16개 전부 통과