From 4a01133032096da8a63ec570a29ddda458238fc6 Mon Sep 17 00:00:00 2001 From: D0ubleD0uble <15200182+D0ubleD0uble@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:37:26 -0600 Subject: [PATCH] docs: fix the stale Unreleased entry and the mismatched header() numbers (#778) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV --- CHANGELOG.md | 38 ++++++++++++++++------------------ SECURITY.md | 7 ++++--- docs/incremental-decoding.md | 6 ++++-- src/incremental.rs | 15 +++++++------- src/pipeline/header.rs | 8 +++---- tests/support/header_oracle.rs | 4 ++-- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2806a9fc..1e3e15ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,7 +87,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). it, `list[i]` or `.get(i)` for one item, `.len()` and `.is_empty()` as before, and `.to_vec()` or `Vec::from(list)` where you need a `Vec`. It compares equal to a slice, `Vec` or array of the same items, either way - round. It has no public constructor (#769). + round. It has no public constructor but `Default`, an empty list (#769). - `IncrementalDecoder::header` leaves out of the metadata a last box of length 0 after the codestream of a type the metadata reports (`xml `, `uuid`, `jp2i`, `uinf`, `rreq`), as more bytes can still change it. `finish`, @@ -137,23 +137,21 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). keeps a key of it, not a copy. In a JP2 file a call also reads the boxes before the codestream again, goes on with the walk to the codestream's end and the walk of the boxes after it from where the last call left - them, reads each header box after the codestream once, and copies the - boxes the metadata reports (`xml `, `uuid`, `jp2i`, `uinf` and the first - `rreq`). The decoder keeps the walks past the boxes before the - codestream, with 24 to 48 bytes for each box after the codestream that - the metadata reports, for as long as it lives, a change of options - included, and of the other boxes there nothing but, for a last box of - length 0, a fixed record of where its read stopped. A last box of length - 0 after the codestream runs to the end of the bytes fed: a `jp2h` there - is read on from its last whole child, and a `colr`, `pclr`, `cmap` or - `cdef` that passed is not read again. Any other box there, or one of - those four that has not passed, is checked on at most its first 258 - bytes. That bounds the check, not the copy: such a box of a type the - metadata reports is copied whole into each header returned, so fed 4 KiB - at a time, 16 MiB of a last `xml ` box take 11 s over 4097 calls. A - caller who feeds such a file in small pieces can call `header` less - often. Fed 4 KiB at a time, a file with such a `jp2h` of a million - 8-byte children takes about 50 ms in all (#756, #758). + them, reads each header box after the codestream once, and reads each + box the metadata reports (`xml `, `uuid`, `jp2i`, `uinf` and the first + `rreq`) once, into lists that later headers share (see the #769 entries + below). The decoder keeps the walks past the boxes before the + codestream for as long as it lives, a change of options included. Of + the boxes after it, it keeps a 24-byte record for each box the metadata + reports only until the lists hold it, and of the other boxes there + nothing but, for a last box of length 0, a fixed record of where its + read stopped. A last box of length 0 after the codestream runs to the + end of the bytes fed: a `jp2h` there is read on from its last whole + child, and a `colr`, `pclr`, `cmap` or `cdef` that passed is not read + again. Any other box there, or one of those four that has not passed, + is checked on at most its first 258 bytes. Fed 4 KiB at a time, a file + with such a `jp2h` of a million 8-byte children takes about 50 ms in + all (#756, #758). - For the tiles over a cap, the decoder keeps the walk of the tile-parts and the counts of the tiles' own headers, about 140 bytes for each tile counted under its own header and up to 9 bytes for each other @@ -231,8 +229,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - `IncrementalDecoder::header` reads each box the metadata reports once, and each later header shares the lists of those boxes and their payloads. Fed 4 KiB at a time, a last `xml ` box of length 0 of 16 MiB - took about 5 s over 4097 calls and takes about 7 ms, and a million 8-byte - `xml ` boxes took about 7 s over 2049 calls and take under 60 ms, less + took 4.4 to 5.0 s over 4097 calls and takes 6 to 14 ms, and a million + 8-byte `xml ` boxes took about 7 s over 2049 calls and take 37 to 75 ms, less than one read of the file. A payload of up to 15 bytes is held in its entry and the longer ones read together share one allocation, so the metadata holds up to about 3.2 bytes for each byte of metadata boxes diff --git a/SECURITY.md b/SECURITY.md index f3f4d9d6..96cfa5f2 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -114,8 +114,8 @@ its calls, `header` also holds: payload of over 15 bytes, its bytes, in an allocation shared with the payloads read in the same call, behind a 16-byte header (8 on a 32-bit target). That is at most about 3 bytes for each byte of such boxes fed, - whatever the pieces: 3.1 measured for 8-byte `xml ` boxes, 2.7 for 9-byte ones, and 2.4 for 24-byte - ones fed one box a call. + whatever the pieces: 3.1 measured for 8-byte `xml ` boxes, 2.7 for 9-byte + ones, and 2.4 for 24-byte ones fed one box a call. The `IncrementalDecoder::header` rustdoc gives each of these in full (see also "Work and memory" in @@ -151,7 +151,8 @@ service](docs/resource-bounds.md#figures-for-a-decode-service). times the input plus 128 KiB (see "The sample limit" in [`docs/resource-bounds.md`](docs/resource-bounds.md)). The JP2 box walk keeps a 24-byte record for each box it reads or reports and for each box - after the codestream that OpenJPEG reads or the metadata reports, and the image's metadata keeps an entry and a copy of + after the codestream that OpenJPEG reads or the metadata reports, and the + image's metadata keeps an entry and a copy of the payload for each `xml `, `uuid`, `jp2i`, `uinf` and `colr` box: a payload of up to 15 bytes in the entry, and the longer ones read together in one allocation. So a file padded with small metadata boxes holds up to about diff --git a/docs/incremental-decoding.md b/docs/incremental-decoding.md index 42694217..d9fed026 100644 --- a/docs/incremental-decoding.md +++ b/docs/incremental-decoding.md @@ -398,8 +398,10 @@ them whole, into lists kept with the walk after the codestream (`jp2::Lists`), and each later header shares those lists (`MetadataList`) and their payloads (`Payload`). A list is a table of blocks of 64 entries, each block set once, so a header that shares it keeps what it had while a -later call adds blocks after it. Fed 4 KiB at a time, a last `xml ` box of -length 0 of 16 MiB takes 7 to 9 ms over 4097 calls, about one read of the +later call adds blocks after it. An old header also keeps alive the blocks that +later calls set in its shared table, at most about twice its own blocks. Fed 4 +KiB at a time, a last `xml ` box of length 0 of 16 MiB takes 6 to 14 ms over +4097 calls, about one read of the file (4.4 to 5.0 s before, when each call copied it), and a million 8-byte `xml ` boxes take 37 to 75 ms over 2049 calls, under one read of the file (about 7 s before, when each call built the lists of every box so far). So a diff --git a/src/incremental.rs b/src/incremental.rs index 7296ae40..1889c85a 100644 --- a/src/incremental.rs +++ b/src/incremental.rs @@ -453,7 +453,7 @@ impl IncrementalDecoder { /// `jp2i`, `uinf`, `rreq`) is left out of the header, as more bytes can /// still change it; [`finish`](Self::finish) and [`refine`](Self::refine) /// report it. Fed 4 KiB at a time, a last `xml ` box of length 0 of 16 MiB - /// takes 6 to 12 ms over 4097 calls, one to a few reads of the file, most + /// takes 6 to 14 ms over 4097 calls, one to a few reads of the file, most /// of it the calls' own cost of about 2 µs each, and a million 8-byte /// `xml ` boxes take 37 to 75 ms over 2049 calls, under one read. So a call /// costs the main header, the boxes before the codestream, and the child of @@ -511,12 +511,13 @@ impl IncrementalDecoder { /// bytes (40 for a `uuid`, 56 for a `uinf`; on a 32-bit target 20, and 36 /// for both) and, for a payload of over 15 bytes, its bytes, in an /// allocation shared with the payloads read in the same call, behind a - /// 16-byte header (8 on a 32-bit target). That is about 3 bytes at most for each byte of such - /// boxes fed, whatever the pieces: a million 8-byte `xml ` boxes after the - /// codestream keep 25.8 MB, 3.1 bytes for each byte of them, and a million - /// of 9 bytes 2.7, fed 4 KiB or one box at a time. Fed 4 KiB at a time, the - /// 2049 calls on the 8-byte boxes take under one read of the file in all. A - /// call made while another thread is in one reads from the start. + /// 16-byte header (8 on a 32-bit target). That is about 3 bytes at most + /// for each byte of such boxes fed, whatever the pieces: a million 8-byte + /// `xml ` boxes after the codestream keep 25.8 MB, 3.1 bytes for each byte + /// of them, and a million of 9 bytes 2.7, fed 4 KiB or one box at a time. + /// Fed 4 KiB at a time, the 2049 calls on the 8-byte boxes take under one + /// read of the file in all. A call made while another thread is in one + /// reads from the start. pub fn header(&self) -> Result> { // A call on another thread holding the lock reads from the start. A // call that panicked may have left the walk half done, so it is diff --git a/src/pipeline/header.rs b/src/pipeline/header.rs index 7841903a..cc812059 100644 --- a/src/pipeline/header.rs +++ b/src/pipeline/header.rs @@ -808,10 +808,10 @@ impl Over { /// of 24 bytes (40 for a `uuid`, 56 for a `uinf`; on a 32-bit target 20, and /// 36 for both) and, for a payload of over 15 bytes, its bytes in a chunk /// shared with the payloads read in the same call, behind a 16-byte header -/// (8 on a 32-bit target). So about 3 bytes at most for each byte of those boxes fed, whatever the -/// pieces: a million 8-byte `xml ` boxes keep 25.8 MB, 3.1 bytes for each -/// byte of them, and a million of 9 bytes 2.7, fed 4 KiB or one box at a -/// time. +/// (8 on a 32-bit target). So about 3 bytes at most for each byte of those +/// boxes fed, whatever the pieces: a million 8-byte `xml ` boxes keep 25.8 +/// MB, 3.1 bytes for each byte of them, and a million of 9 bytes 2.7, fed 4 +/// KiB or one box at a time. #[derive(Default)] pub(crate) struct HeaderCache { /// Boxed, so a decoder with nothing kept holds a pointer. diff --git a/tests/support/header_oracle.rs b/tests/support/header_oracle.rs index 4dada7ec..b7f7e05d 100644 --- a/tests/support/header_oracle.rs +++ b/tests/support/header_oracle.rs @@ -85,8 +85,8 @@ pub fn oracle(prefix: &[u8], options: &DecodeOptions) -> String { /// malformed. A box read whole by its length reads the same. So an entry is /// left out where it is the last of its list and the read of `prefix` and a /// zero byte gives another entry there, or none. The lists have no public -/// constructor, so the entry is left out of the text, which lists them as a -/// slice's `Debug` does. +/// constructor but `Default` (an empty list), so the entry is left out of the +/// text, which lists them as a slice's `Debug` does. pub fn without_open_box(header: &Header, prefix: &[u8], lenient: &DecodeOptions) -> String { let mut text = format!("{header:?}"); let Some(jp2) = header.jp2.as_ref() else {