
A malicious file set for a document viewer: ZIP bombs, CFB loops and XSS, generated and wired into tests
If your app opens received files, commit a generator and an expected-verdict table instead of hostile samples. Unit tests check 50 rows; rendering is checked on a device.
Building the SugarDoc HWP viewer 8/8
Sooner or later, an app that opens files from chat or email receives one built to hurt it: a ZIP bomb that inflates to 1 GiB, a sector chain that loops forever, a script hidden in the text (XSS). SugarDoc, our Android viewer for HWP (the Korean word-processor format), HWPX and PDF, keeps a generator for 50 such documents, written with only the Python standard library, plus a table of each file's expected verdict, and a unit test checks every row against the Kotlin guards. No hostile file is committed. The set started at 36 files on October 5, 2026 and reached 50 the same day after a review. The test guards the container verdicts; whether a script runs on screen is checked separately on a device.
Contents (12)
- One row holds the file and its expected verdict
- The ratio rule stops some bombs; budgets stop the rest
- A visited set stops CFB loops, but each path needs its own row
- XSS rows only get a container verdict
- A review showed the 75/75 report did not cover every guard
- On Windows, the test was silently skipping
- 0 of 99 CI runs passed: CI can't gate the set
- A generator instead of samples, and rhwp's unmeasured limits
- No real encrypted files, and a 29.1 s TIMEOUT on the S21
- Write the verdicts first, then remove guards to check them
- Still to do: a green CI, no skips, and the webTests wiring
- Frequently asked questions
One row holds the file and its expected verdict
generate.py is 682 lines. It writes ZIP, CFB (Compound File Binary, the container inside HWP 5 files), HWPX and PDF by hand with the standard library and emits 50 files plus manifest.tsv. It is deterministic and its output is never committed. There are 10 families, among them ZIP bombs, parser differences, pixel bombs and CFB, plus 2 control rows.
file family sniff guard preview
bomb_1gb_lying.hwpx zip_bomb HWPX RATIO shown
multi_bomb_noisy.hwpx zip_bomb HWPX TOTAL_BYTES shown
cfb_bomb.hwp cfb_bomb HWP5 LOOP shown
xss_text.hwpx content HWPX OK shown
The set test reads the table row by row and compares it with the format sniffer, the ZIP and HWP 5 guards and the preview. It collects every mismatch into one failure, and it also fails if a single file takes 1,000 ms or the table has fewer than 30 rows. A Gradle task builds the set ahead of the unit tests, and the pre-release check script calls the same tests. On bomb rows, "shown" means the viewer refuses the engine and shows the preview instead.
The ratio rule stops some bombs; budgets stop the rest
ZIP bombs meet three layers. A 1 GiB entry with an honest size ends at ENTRY_TOO_LARGE before anything inflates. bomb_1gb_lying.hwpx declares 1000 bytes, so it reaches the ratio rule, which counts real output: past 1 MiB, more than 1000:1 is refused. In the October 5 JVM run both took 2 ms, and the file carrying the 1 GiB was 1.07 MB.
The rule only just catches the set's zero bomb. Recomputing the generator's deflate in memory gives about 1,012:1, 1.2% over the limit. The code comment's 1030:1 is closer to deflating the same zeros in one pass, about 1,029:1 when recomputed; the generator writes separate blocks, so it lands a little lower. multi_bomb_noisy.hwpx scatters random bytes between the zeros and lands near 103.8:1 per entry, far under the rule. It has 16 entries of 40 MiB, 640 MiB in all, and the fourth pushes it past the 128 MiB real-byte total for everything outside BinData/. BinData/ is the folder for images inside a document, with its own total limit (256 MiB by default); everything else counts against the 128 MiB, including images placed outside that folder.

The 64 MiB per-entry and 128 MiB total budgets are normal-document maximums plus a margin. Across 46 HWPX files in a local corpus, the largest entry outside BinData/ was 2.9 MB and the largest total 3.4 MB, which the code records as a 20x margin.
A visited set stops CFB loops, but each path needs its own row
In cfb_bomb.hwp a stream's FAT chain (the sector link table) points back to its own start. The CFB reader walks chains and directories with a visited set and a length cap, so the second visit to a sector ends in LOOP.
The set still left another path to the same flaw, and it surfaced on October 24. When we tested two stream-reading functions separately in the guard-removal table, one row passed with the guard deleted. That function is used by the code that overwrites the preview streams of a received file; it had no loop test, and the set test never reaches it. It has its own loop test now.
XSS rows only get a container verdict
xss_text.hwpx carries markup as body text and xss_font.hwpx carries it in a font name. The set test only decides that both are containers the viewer may open. Our topic list said XSS ran on every build; reading the code again showed that rendering is checked in three other places.
- A device instrumentation test opens each document and audits the DOM. It needs the documents staged on the device and skips without them, and neither CI nor the pre-release script runs it. On October 5, on debug builds on a Galaxy S21 (WebView 153) and an API 33 emulator (WebView 103), xss_text, xss_font and nest had one script (viewer.js) and zero on* attributes, javascript: values, banned elements or CSS url() rules.
- A node engine test renders the generated files with rhwp and inspects the first two sanitized pages. If the files aren't in a cache it skips, and the web test task doesn't pass the set's path.
- A node unit test runs under the web test task but uses only inline strings.
In the WebView, the app's request handler answers every request with a bundled asset, a one-time document token or a 403. The early test build returned null, which left only blockNetworkLoads and the CSP in the way, so the product forbids null.
The CSP goes on every response, 403s included, because a module Worker obeys the CSP of its own response; a CSP on viewer.html alone would leave the Worker unrestricted. Raw SVG from the engine is parsed into an inert document and sanitized against an allow-list before it reaches the page.
The canary test tries to reach a local server. The main thread's 14 paths, the Worker's 9 and the external_link document all scored 0 hits, while an unhardened control WebView scored 1. Without the control, you can't tell a hardened page from a broken test that never reaches the server.
A review showed the 75/75 report did not cover every guard
The set and the guards were co-authored by Claude. The October 5 report for that build stage said removing 75 guards failed all 75 and marked four completion criteria as met. Those 75 were hand-picked. A review the same day found about 15 untested guards in the ZIP and CFB readers, plus the HWP 5 guard's pixel-total check.
The HWP 5 guard counted only the compressed size of streams. After the review it inflates chunk by chunk and counts real bytes. The ZIP guard gained the budget outside BinData/, and an image whose size can't be read is now refused. The set grew from 36 to 50 files and guard removal reached 146/146.
The generator was wrong too. A bug in how it wrote CFB sibling links surfaced on the first comparison with the Kotlin verdicts.
The repository doesn't record who did that review, and it has no record of a person editing the code. The operator's rule that a guard must fail when removed went into that stage's criteria and produced the 75/75 measurement. The 64 MiB and 128 MiB budgets still carry an owner-confirmation tag in the code.
On Windows, the test was silently skipping
We moved the build machine to Windows on October 18, 2026. The build script looked on PATH for a file named exactly python3, Windows has python.exe, so the task that builds the set was never registered, the set's directory property stayed empty and assumeTrue skipped the test.
An early commit on October 23 says the tests had never run on Windows since the move, and logs a full unit run as 1,254 tests, 0 failed, 7 skipped. It doesn't name the seven. About eight hours later the lookup was fixed, with the verification line "1 test run, 0 skipped, 51 set files" (50 documents plus the manifest). Nothing compared skips by name. How a skip disappears into a green run is covered in Silently skipped tests keep CI green. With no python, this test still skips; only the pre-release script stops with BLOCK. The same script calls a missing node a "failure, never a skip".
The operations log says it doesn't know which machine built the 1.2.0 and 1.3.0 AABs, so we can't say whether a release between October 18 and 23 skipped the set.
0 of 99 CI runs passed: CI can't gate the set
As of November 7, 2026, GitHub Actions lists 99 CI runs and none succeeded (78 failed, 21 cancelled). The one run whose log we read did not fail on python. Set generation printed wrote 50 files, the build failed on one unit test in another module (the design system), and the log has no task line for the module that holds the set test. All 99 runs are pushes to main, and main has no branch protection, so a failing CI doesn't hold code back. What stops a release AAB when the set fails is the pre-release script, and running that script is left to the release checklist.
A generator instead of samples, and rhwp's unmeasured limits
The generator's docstring says "no real documents, no binary blobs", so what stays in the repository is 682 lines and the expected verdicts. The test compares every row, so in the docstring's words the generator and guards "cannot drift apart". Unlike sample files, a changed verdict or file content shows up as a code diff rather than a binary, and no hostile file stays in the repository. The same files go into device E2E, where the S21 and S20 each passed the manifest 50/50.
The set only covers known patterns, so it guards against regressions; finding unknown inputs is a fuzzer's job, and we found no fuzzing record in the repository's docs or tests.
Leaving limits to rhwp was rejected. The wasm contains text about an inflate limit, but nobody measured it, so the HWP 5 guard's comment says the guard "does not rely on them".
No real encrypted files, and a 29.1 s TIMEOUT on the S21
The flags family only sets flag bits; real encrypted and DRM documents aren't in the set.
The 1,000 ms cap is JVM time on a development machine. paras_50k.hwpx, 50,000 paragraphs, came to 1,220 pages and parsed in about 21 s under node 20 with rhwp 0.8.6 on a desktop on October 5, 2026, between the 10 s slow prompt and the 30 s forced fallback. On the S21 its first page took 26.1 to 27.9 s or hit TIMEOUT at 29.1 s, and the emulator hit TIMEOUT at 29.3 s.
In the October 5-6 device E2E run, the 64-level nested table in nest.hwpx reported itself drawn while showing a blank page. After the follow-up fix, release builds ended on the damaged-file screen with "open with another app" in 3 of 3 runs. The set test can't see this defect.

Write the verdicts first, then remove guards to check them
- Split threats into families and write each file's expected verdict first.
- Write a deterministic generator with no outside dependencies that emits the files and the manifest together and prints how many it wrote.
- Have a test compare the manifest row by row, and assert a per-file time cap and a minimum row count.
- Set budgets from a corpus of normal documents: take the maximums and multiply by a margin. This app went from 46 files, 2.9 MB and 3.4 MB to 64 MiB and 128 MiB.
- Attach it to the unit test task. This app still skips when python is missing, but don't leave a security set skippable. The snippet below is a proposal, not code from the repository.
val dir = System.getProperty("sugardoc.malicious")?.let(::File) if (System.getenv("CI") == "true") check(dir?.isDirectory == true) { "security set missing" } assumeTrue(dir != null && dir.isDirectory) - Measure rendering on a device, and first confirm an unhardened control WebView scores a hit.
- Remove guards one at a time and watch tests fail. If a guard sits on two paths, give it two rows.
Still to do: a green CI, no skips, and the webTests wiring
Three things were not done as of November 7, 2026: fixing the test failure in another module so CI runs to the end, turning the skip into a failure on a CI machine with no python, and passing the generated set to the web test task. The log we read doesn't show whether the set test runs in CI without a skip, and we did not download the report files.
Frequently asked questions
How do you stop ZIP bombs in an Android app?
Ignore declared sizes and count real bytes while inflating. This app combines a per-entry cap, a 1000:1 ratio rule past 1 MiB and total budgets.
Can HWP or HWPX files be decompression bombs?
Yes. HWPX is a ZIP, and HWP 5 keeps deflate streams inside CFB. The set has rows that inflate to 1 GiB in both formats.
Sources: the SugarDoc repository's git history, code, design decision record, device E2E reports and GitHub Actions history (queried November 7, 2026). Compression ratios were recomputed with Python 3.12 zlib.
This note is written from values SugarMount measured itself; an AI coding agent was used to draft it.