You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
improvement(files): harden untrusted document preview and parsing (#6420)
* improvement(files): harden the docx preview renderer
* fix(files): tighten the OOXML archive size guard against parser OOM
* fix(files): apply the per-entry OOXML cap to every part, not just XML names
/** Hard ceiling on the summed declared uncompressed size of all entries. */
42
43
maxTotalUncompressedBytes: number
44
+
/** Hard ceiling on any single entry's declared uncompressed size — the parser materializes an individual part (e.g. `document.xml`) into a DOM, or base64-embeds media, at a footprint many times the part size. */
45
+
maxEntryUncompressedBytes: number
43
46
/** Maximum allowed expanded:compressed ratio across the whole archive. */
44
47
maxCompressionRatio: number
45
48
/** The ratio check only applies once the expanded size exceeds this floor, so small files are never flagged. */
46
49
ratioCheckFloorBytes: number
47
50
}
48
51
49
-
constONE_GIBIBYTE=1024*1024*1024
50
52
constONE_HUNDRED_MEBIBYTES=100*1024*1024
53
+
constONE_HUNDRED_FIFTY_MEBIBYTES=150*1024*1024
54
+
constSIXTY_FOUR_MEBIBYTES=64*1024*1024
51
55
52
56
/**
53
-
* Defaults sized against the 100 MB compressed-input cap of the parse pipeline.
54
-
* A legitimate Office document stays well under 1 GiB expanded; the bombs
55
-
* described in the threat model expand to multiple gigabytes.
57
+
* The downstream parsers (mammoth, SheetJS, officeparser) build a full in-memory
58
+
* DOM/object graph whose peak heap is many times the XML size — measured at
59
+
* ~900 MB resident for 32 MB of expanded WordprocessingML, and mammoth then
60
+
* parses a second time for HTML. The old 1 GiB ceiling let a ~3.5 MB archive
61
+
* expand past what the process could hold and OOM it. The total and per-entry
62
+
* caps here keep a single parse's peak within a modest container's budget while
63
+
* still admitting all but pathologically large documents.
0 commit comments