fix(player): an entry inflates no further than the size its archive declares, and the worker parses no JSON over 16 MB
Merged
AL
18h ago+337+337+012345678901234567890123456789-16-16-01234567890123456789
Two limits on what an archive's sizes can cost the player. Found in a review of the player's code, with no report from outside.
What was open
- The native
DecompressionStreamknows no declared size. An extraction in the Jobs worker, the warm and a reader over an archive still downloading inflate with it, so an entry could inflate past the size its archive declares: 65 kB inflated to 64 MB under a declared 10 bytes and was recorded in the chunk store as complete. Without end, it fills the store, and each refused write evicts another idle package. - A stored entry went down the same path as it was: one that declared 10 bytes gave its 4 MB to a reader over an archive still downloading (found in cubic's review).
- zip.js, which reads for a reader over the central directory, already refuses either entry as it streams, so that path was not open.
- The Service Worker parsed
h5p.json,library.jsonandcontent.jsonwhole, whatever their size: a 33 kB archive made it parse 32 MB.
Fix
inflated(shared/stream-utils.ts) takes the entry, counts its output, a stored entry's too, and fails withbad-archivepast the declared size (heldTo). Its three callers pass the entry: the extraction, the warm andPackageReader.inflateDirect.PackageReader.jsonrefuses, unread, an entry that declares or carries more thanPARSED_MAX_SIZE(16 MB), and every JSON parse in the worker goes through it:readManifest, the content's parameters, the addons and the server'sreadJson.- An oversized
h5p.jsonfails the package, and an oversizedlibrary.jsonthe load that needs it, with the limit in the message. - An oversized
content.jsonis treated as one that cannot be parsed, and the addon scan passes over an oversizedlibrary.json, as over one that does not parse. - The limit is on the larger of what the entry declares and what the archive carries for it (
parsedSize), and a read is held to the declared size. - The largest
content.jsonof 89 real packages is 150 kB.
- An oversized
design/security.md: the rule, and what stays unbounded.
Not bounded
- The archive's index, which zip.js reads whole whatever its entry count.
- An entry of an honest, enormous size: a large package like any other, which evicts idle ones to fit.
Tests
tests/unit/declared-size.test.ts, twelve tests: the native path cut off at the declared size, deflated and stored; an honest entry passed whole; nothing complete in the chunk store; both kinds of reader; and the JSON limit for each of the three files, for a stored file that carries more than it declares, for one that carries more than the limit, and at the limit itself.tests/unit/warm.test.ts: an entry past its size is passed over, and the rest lands.tests/browser/jobs-worker.test.ts: through the real Jobs worker, the extraction fails withbad-archiveand keeps no chunk.- Player: type check, 414 unit tests, 215 browser tests in Chromium with the slow files,
pnpm comments. - Not run: Firefox and WebKit.
Release: a player patch (SECURITY.md: a security fix ships in any release). An entry that runs past its declared size was read before and fails now; a JSON file over 16 MB was parsed before and is refused now.
Summary by cubic
Stops a hostile archive's sizes from costing the player more than declared: an entry now inflates no further than the size its archive declares, and the worker parses no JSON over 16 MB.
inflated()counts output and fails withbad-archivepast the declared size, for deflated and stored entries alike. The nativeDecompressionStream, which knows no declared size, previously inflated entries to their end; stored entries were returned as carried.PackageReader.jsonrefuses, unread, a JSON entry declaring or carrying more thanPARSED_MAX_SIZE, as parsing holds it whole. An oversizedh5p.jsonorlibrary.jsonfails the package, while an oversizedcontent.jsonis treated as one that cannot be parsed; the addon scan passes over such alibrary.json.
Behavior change: entries that inflated past their declared size and JSON over 16 MB were accepted before and are now refused. This is a security fix, shipped in a player patch.