@cosyte/dicom 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +199 -0
- package/README.md +3 -1
- package/dist/index.cjs +135 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +241 -116
- package/dist/index.d.ts +241 -116
- package/dist/index.mjs +135 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,204 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 21d42f5: Scan a file by its CONTENT in the repository's PHI gate (`scripts/phi-scan.ts`), which is developer
|
|
8
|
+
tooling and not part of the published surface.
|
|
9
|
+
|
|
10
|
+
`scanTarget` branched on the file's extension before it read a byte: `.json`, `.txt`, `.md` and
|
|
11
|
+
`.csv` ran the text sweep and the base64 decode and returned, so the DICOM-aware sweep never ran on
|
|
12
|
+
one whatever its bytes were. A file whose raw bytes are a Part 10 object was therefore never scanned
|
|
13
|
+
as one if it happened to be named `.md`, which a de-identification report, a bug repro or a fixture
|
|
14
|
+
saved under the wrong extension plausibly is.
|
|
15
|
+
|
|
16
|
+
What that cost is narrower than "a second opinion", and the fixture is built to show it: only the
|
|
17
|
+
tag table can see a **single-component** `(0010,0010)`, because that shape carries no caret for the
|
|
18
|
+
text sweep's person-name pass to match. Measured on `08ed3ee` over one object, the same bytes exited
|
|
19
|
+
1 as `.dcm`, `.bin` and `.dat`, and 0 with `OK - no hits` as `.md`, `.txt`, `.json` and `.csv`.
|
|
20
|
+
Preamble-less, the same.
|
|
21
|
+
|
|
22
|
+
The remedy is the DELETION of the branch, and that is what makes it safe rather than a net leak.
|
|
23
|
+
`scanDicom` gives up quietly at an undefined-length Sequence (PS3.5 2026c section 7.5.2 defines
|
|
24
|
+
`0xFFFFFFFF` as one of two Sequence delimitations, both of which decoders shall support, and section
|
|
25
|
+
7.1 orders tags ascending, so `(0008,1110)` precedes `(0010,0010)` in a conformant file), so routing
|
|
26
|
+
a file to it INSTEAD of the text sweep has previously taken a name from exit 1 to exit 0. The removed
|
|
27
|
+
branch's two calls were the text sweep and the base64 decode; the branch that replaces it makes the
|
|
28
|
+
same two unconditionally and adds one conditional DICOM sweep. Hits are only ever appended, so the
|
|
29
|
+
hit set, the totals and the exit code are a strict superset on every input.
|
|
30
|
+
|
|
31
|
+
That superset was checked mechanically over 11 objects times 7 extensions, 77 cells: 65 identical,
|
|
32
|
+
12 strictly more reported, 0 cells that lost an exit code or a reported value. Every fixture was
|
|
33
|
+
verified through this package's own parser before any zero it produced was believed. The scan of the
|
|
34
|
+
repository's real corpus is byte-identical, exit code and output alike.
|
|
35
|
+
|
|
36
|
+
Two residuals are unchanged and disclosed rather than closed: the DICOM sweep still reports nothing
|
|
37
|
+
about the bytes it never read, and the hit array is still unbounded in memory. The matrix, the
|
|
38
|
+
superset check and the reason the first of those is a separate slice are in
|
|
39
|
+
`documentation/agent-notes/dicom-phi-scan-name-dispatch.md`.
|
|
40
|
+
|
|
41
|
+
- 028fe85: Close a silent halt in the repository's PHI gate (`scripts/phi-scan.ts`), which is developer
|
|
42
|
+
tooling and not part of the published surface.
|
|
43
|
+
|
|
44
|
+
`scanDicom` gives up quietly at the first Data Element header it cannot read, and an
|
|
45
|
+
undefined-length Sequence is one of those (PS3.5 2026c section 7.5.2 defines it as one of two
|
|
46
|
+
delimitations, both of which decoders shall support). The text sweep behind it ran only when
|
|
47
|
+
`isDicom` answered false, so a **preamble-ful** Part 10 object had nothing behind the halt: the
|
|
48
|
+
identical dataset was reported without a preamble and missed with one, and the gate printed
|
|
49
|
+
`OK - no hits` over a name-bearing `(0010,0010)`. The preamble is not part of the dataset, so it
|
|
50
|
+
cannot decide who is owed a text sweep.
|
|
51
|
+
|
|
52
|
+
The text sweep now runs on every binary target, and `scanEmbeddedObjects` runs it on the object it
|
|
53
|
+
decodes as well, where the base64 hides the name from the enclosing page. Both are additions beside
|
|
54
|
+
`scanDicom`, never replacements for it.
|
|
55
|
+
|
|
56
|
+
The accepted cost is false positives over binary values. Which recognizer produces them, and how
|
|
57
|
+
many, is a property of the payload's byte histogram rather than of the scanner: over 8 MiB of
|
|
58
|
+
synthetic pixel data the measured count runs from zero to five figures. The table, and the residuals
|
|
59
|
+
left open, are in `documentation/agent-notes/dicom-scandicom-silent-halt.md`.
|
|
60
|
+
|
|
61
|
+
Also closes a pre-existing refusal on the same route: the base64 run matcher was a greedy regular
|
|
62
|
+
expression, and one multi-megabyte run overflowed V8's backtrack stack, exiting 2 rather than
|
|
63
|
+
scanning. It is a forward scan now, yielding the same runs.
|
|
64
|
+
|
|
65
|
+
- 99da18f: Make the repository's PHI gate (`scripts/phi-scan.ts`) report the bytes its DICOM sweep never read.
|
|
66
|
+
This is developer tooling and not part of the published surface.
|
|
67
|
+
|
|
68
|
+
`scanDicom` stops at the first Data Element header it cannot read and said nothing about what came
|
|
69
|
+
after it, so a run printed `OK - no hits` over a file whose tag table it had abandoned partway
|
|
70
|
+
through. The way in is conformant: PS3.5 2026c section 7.5.2 defines an undefined-length Sequence as
|
|
71
|
+
one of two delimitations, both of which decoders shall support, and section 7.1 orders tags
|
|
72
|
+
ascending, so `(0008,1110)` precedes `(0010,0010)`. Encapsulated pixel data has the same shape.
|
|
73
|
+
|
|
74
|
+
Each halt is now recorded per file and printed as a `PARTIAL:` line, and the word `OK` is withdrawn
|
|
75
|
+
from the clean line when any file has one. The line carries a path, two counts and a reason from a
|
|
76
|
+
closed table: no tag, no VR, no value and no byte of the object, because the bytes at a halt are
|
|
77
|
+
exactly the bytes that did not read as a header. The tally is bounded by the number of files rather
|
|
78
|
+
than by anything an object can choose, so it needs no cap and cannot be pushed off the report by a
|
|
79
|
+
file loud enough to bury its own hits.
|
|
80
|
+
|
|
81
|
+
The exit code deliberately does not move. Nothing was found, nothing refused the scan, the same
|
|
82
|
+
disclosure would fire on input section 7.5.2 makes legal, and folding it into exit 2 would mask a
|
|
83
|
+
real hit whenever both were present. A CI job that reads only the exit code therefore still cannot
|
|
84
|
+
see this, which is disclosed rather than claimed away.
|
|
85
|
+
|
|
86
|
+
Proved over 13 objects x 5 carriers x 3 cap settings: exit code and hit lines identical in all 195
|
|
87
|
+
cells, 60 outputs identical, 105 strictly larger, 30 differing only by the withdrawn `OK` line, 0
|
|
88
|
+
violations. The generator ships as `scripts/measure-phi-scan-unread.ts` so the table can be
|
|
89
|
+
re-derived. What the disclosure does and does not carry, and the residuals left open, are in
|
|
90
|
+
`documentation/agent-notes/dicom-phi-scan-unread-tail.md`.
|
|
91
|
+
|
|
92
|
+
- 783f667: Let the repository's PHI gate (`scripts/phi-scan.ts`) finish writing its report before it exits.
|
|
93
|
+
This is developer tooling and not part of the published surface.
|
|
94
|
+
|
|
95
|
+
The script ended `process.exit(run())`. `process.exit()` tears the process down without waiting for
|
|
96
|
+
stdio that libuv has accepted but not yet written, and under every caller that matters this script's
|
|
97
|
+
stderr is a **pipe**: `spawnSync` in this repo's own suite, and the shell pipeline a CI job runs it
|
|
98
|
+
in. A pipe write that cannot complete immediately is queued and flushed on a later loop turn, which
|
|
99
|
+
`process.exit()` never allows, so `report()` returning was not the same as its bytes having left the
|
|
100
|
+
process.
|
|
101
|
+
|
|
102
|
+
**The failure mode is a gate defect, not a cosmetic one.** The exit code is computed from
|
|
103
|
+
`hits.length` and was always right, so a truncated report is a run that REFUSES while under-naming
|
|
104
|
+
what it found, and the bytes it drops are the END of the report: the last hit lines and the total,
|
|
105
|
+
which is the part a reader trusts to say how much there was.
|
|
106
|
+
|
|
107
|
+
This was red on `main`. `ci / verify (24, ubuntu-latest)` is a required check and it failed on
|
|
108
|
+
`08ed3ee` and `21d42f5`, both times on `countHitLines(...) === 200` reading 193, and on `#106`'s PR
|
|
109
|
+
head reading 191, with `verify (22)` green throughout and the exit code correct in every case.
|
|
110
|
+
|
|
111
|
+
The scan is deterministic, so the hit COUNT cannot vary between runs: the fixture is 200 distinct
|
|
112
|
+
tokens and the recognizers are plain global regexes over the whole file. What varied is what
|
|
113
|
+
arrived. Measured on `21d42f5` with the reader stalled, 5,000 small stderr writes: `process.exit(1)`
|
|
114
|
+
delivered 784 lines, about one 64 KiB pipe, on 3 of 3 runs; `process.exitCode = 1` delivered 5,000
|
|
115
|
+
on 3 of 3. Node 22.23.1 and 24.19.0 behaved identically there, so the version split is scheduling
|
|
116
|
+
and not stdio semantics. The CI failure itself reproduced on the real script and the real fixture
|
|
117
|
+
once the reader was made to lose (single-page pipes plus CPU contention): **30 of 60 runs truncated,
|
|
118
|
+
counts including 190, 191 and 192, exit 1 every time; 0 of 60 with this change.**
|
|
119
|
+
|
|
120
|
+
Not calling `process.exit()` has a cost, and it is paid here rather than discovered later: it makes
|
|
121
|
+
a late stdio error reachable. A write to a pipe whose reader has gone fails with `EPIPE` on a later
|
|
122
|
+
tick, after `run()` has returned, so `run()`'s try/catch cannot see it and Node's default
|
|
123
|
+
unhandled-`'error'` path exits 1, the one code that means "PHI was found". Without a listener a
|
|
124
|
+
clean corpus went 0 to 1 and an invocation error went 2 to 1. Both stdio streams now discard a late
|
|
125
|
+
error, which is exactly what `process.exit()` did by making it unreachable, so the exit code stays
|
|
126
|
+
exactly what `run()` returned. **The residual, disclosed and not closed: with a reader that never
|
|
127
|
+
drains at all this script now waits instead of exiting, where `process.exit()` ended it by dropping
|
|
128
|
+
the report.** That is introduced, on `node` and under `tsx` alike. A timeout would re-introduce the
|
|
129
|
+
defect this closes, so it is disclosed rather than answered.
|
|
130
|
+
|
|
131
|
+
It changes what ARRIVES, never what is WRITTEN. Over a draining reader, base and fixed emit
|
|
132
|
+
byte-identical stdout, stderr and exit code across 12 cases spanning all three of the contract's
|
|
133
|
+
exit codes, the per-file print cap at its default and at 0, 1 and 3, the net-leak control and both
|
|
134
|
+
cells of the finding that `report()` is not monotone in `hits` at the cap. Nothing about the cap or
|
|
135
|
+
its non-monotonicity is changed or claimed away here; the printed set simply arrives.
|
|
136
|
+
|
|
137
|
+
Still open and NOT fixed here: `test/helpers/run-script.ts` inherits `spawnSync`'s 1 MiB
|
|
138
|
+
`maxBuffer`, which truncates at roughly 15,400 lines in both exit modes. That is the parent dropping
|
|
139
|
+
bytes it was handed rather than the child failing to hand them over, and it is a different defect.
|
|
140
|
+
|
|
141
|
+
Detail, controls and the superset check: `documentation/agent-notes/dicom-phi-scan-exit-flush.md`.
|
|
142
|
+
|
|
143
|
+
- b784c38: Name the frame a `DicomParseError`'s byte offset is counted in, and correct the universal that was
|
|
144
|
+
defending the bound around it.
|
|
145
|
+
|
|
146
|
+
`err.byteOffset` was the sole locator on the two Tier-3 messages that lost their remaining-bytes
|
|
147
|
+
count, and it is slice-relative inside a defined-length Sequence Item: on one fixture the same
|
|
148
|
+
defect reports `0`, `24` or `40` depending on where inside the Item the offending element sits, while
|
|
149
|
+
that Item's slice begins at absolute offset 202. Nothing on the class said which coordinate system
|
|
150
|
+
the number was in, and the wrong reading is not detectable by a consumer. It is a valid index into a
|
|
151
|
+
buffer that returns a real element, just not the one the diagnostic named. On a fixture engineered
|
|
152
|
+
for the earlier snippet fix, reading the item-relative number against the file lands inside a planted
|
|
153
|
+
`"MR BRAIN SMITHSON "`.
|
|
154
|
+
|
|
155
|
+
**`DicomParseError.offsetFrame` is new and required**, drawn from the new `OFFSET_FRAMES` export
|
|
156
|
+
(`"input"`, `"inflated-dataset"`, `"value-slice"`). **Only `"input"` means the offset indexes the
|
|
157
|
+
buffer you passed in.** The frame is in the `Error.message` suffix as well as on the class, so that
|
|
158
|
+
suffix reads `(offset=N frame=F)` on every Tier-3 fatal and every `{ strict: true }` escalation: a
|
|
159
|
+
string match on it stops matching. `err.code` is unchanged and which files throw is unchanged.
|
|
160
|
+
|
|
161
|
+
The frame's **name** is published and its **origin** is not. Where a slice begins is the sum of the
|
|
162
|
+
declared lengths that reached it, so an error naming its own frame's origin would hand back by
|
|
163
|
+
subtraction the wire field these same messages withhold. Internally the frame's bytes and its name
|
|
164
|
+
travel as one object, so a frame change is one assignment and no call site can move the bytes and
|
|
165
|
+
leave the label behind. It does not make a deliberately mismatched pair impossible, and is not
|
|
166
|
+
described as doing so.
|
|
167
|
+
|
|
168
|
+
**The universal used to justify withholding a declared length, in the README, two package docs and
|
|
169
|
+
two places in the parser, was false and is corrected rather than reworded a second time.** A fatal "about a length field that lies" does not fire
|
|
170
|
+
only when a length field is lying: a spec-clean object cut short by two bytes raises
|
|
171
|
+
`ELEMENT_LENGTH_EXCEEDS_BUFFER` with every declared length honest, and one cut short inside its File
|
|
172
|
+
Meta group raises `FILE_META_GROUP_LENGTH_OVERRUNS` with `(0002,0000)` untouched. Both are measured.
|
|
173
|
+
The bound is right in either reading because the withheld number is four bytes a sender wrote either
|
|
174
|
+
way; the universal was never what made it right.
|
|
175
|
+
|
|
176
|
+
Also replaces an arity pin that did not pin what it claimed. It read
|
|
177
|
+
`Function.prototype.length`, which stops counting at the first defaulted parameter, so a factory that
|
|
178
|
+
had grown exactly the slot the pin refuses would still have read `2` and stayed green.
|
|
179
|
+
|
|
180
|
+
`UNSUPPORTED_TRANSFER_SYNTAX` keeps the behaviour every released version has: its `snippet` slot
|
|
181
|
+
carries PS3.6's own name for the unsupported UID rather than raw bytes, so it is the one fatal whose
|
|
182
|
+
snippet is not a cut of the frame it names. `DicomParseWarning.position` and `Element.byteOffset`
|
|
183
|
+
still carry no frame, and `err.snippet` is still 16 raw source bytes. All three are pre-existing, disclosed, and not closed here. The measurements,
|
|
184
|
+
the residuals, and every clean result with the positive it is pinned beside are in
|
|
185
|
+
`documentation/agent-notes/dicom-diagnostic-locator-frame.md`.
|
|
186
|
+
|
|
187
|
+
- 08ed3ee: Cap the repository's PHI gate (`scripts/phi-scan.ts`) at a per-file number of printed hit lines,
|
|
188
|
+
which is developer tooling and not part of the published surface.
|
|
189
|
+
|
|
190
|
+
`report()` wrote one stderr line per hit with no bound, and the preceding slice widened what reaches
|
|
191
|
+
it: the text sweep now runs over every Part 10 object's bytes, and its recognizers fire on image
|
|
192
|
+
noise at a rate that is a property of the payload's byte histogram. Measured on `b784c38` over 8 MiB
|
|
193
|
+
of synthetic pixel data uniform over `0x41-0x60`, one run wrote 71,447 hits as 6,037,715 bytes of
|
|
194
|
+
stderr.
|
|
195
|
+
|
|
196
|
+
The cap is on **printing only**. The exit code and the reported totals are derived from the hits and
|
|
197
|
+
not from what was printed, so a withheld line cannot turn a refusal into a clean run. It is applied
|
|
198
|
+
**per file**, never globally, so a loud file cannot push a later file's hits off the report. A file
|
|
199
|
+
with lines withheld says so, with the exact remainder. `--max-hit-lines <n>` sets the bound and
|
|
200
|
+
`--max-hit-lines 0` prints every line, reproducing the previous output byte for byte.
|
|
201
|
+
|
|
3
202
|
## 0.0.17
|
|
4
203
|
|
|
5
204
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -338,7 +338,9 @@ The library throws five typed errors, all exported from the package barrel. Warn
|
|
|
338
338
|
|
|
339
339
|
### `DicomParseError`
|
|
340
340
|
|
|
341
|
-
Thrown by `parseDicom` on one of the 4 Tier-3 fatal codes. Carries the byte position, a registry-composed message, and a 16-byte hex `snippet` of the source. **The message is looked up in a frozen registry and its factories take no tag, no wire-length parameter and no count of the bytes left in the buffer**, so none of them can be interpolated
|
|
341
|
+
Thrown by `parseDicom` on one of the 4 Tier-3 fatal codes. Carries the byte position, the **frame** that position is counted in, a registry-composed message, and a 16-byte hex `snippet` of the source. **The message is looked up in a frozen registry and its factories take no tag, no wire-length parameter and no count of the bytes left in the buffer**, so none of them can be interpolated. The reason is not that such a fatal fires only on a lying length field: it fires on an honestly truncated file too, where nothing is fabricated and the transport simply lost bytes. Measured on a spec-clean object cut short by two bytes, `ELEMENT_LENGTH_EXCEEDS_BUFFER` raises with every declared length in the file honest. The bound covers both because the withheld numbers are four bytes a sender wrote either way, and because on the desynchronized reading those four bytes are somebody's name: an under-declaring `ST` carrier holding `"MR BRAIN SMITHSON "` once rendered `declared length=1330858068`, which is `"THSO"`.
|
|
342
|
+
|
|
343
|
+
`err.byteOffset` locates the element, and **`err.offsetFrame` says which coordinate system that number is counted in** (`OFFSET_FRAMES`: `"input"`, `"inflated-dataset"`, `"value-slice"`). Only in `"input"` is it an index into the buffer you passed in. A defined-length Sequence Item is parsed from a slice, so an offset raised inside one counts from that Item, and the same file reports `0`, `24` or `40` for the same defect depending on where in the Item it sits. **Where a slice begins is deliberately not published**, because the distance between two frames is a declared Value Length off the wire. The frame is in the `Error.message` suffix too, which now reads `(offset=N frame=F)`, so a string match on that suffix stops matching. `err.code` is unchanged. `DicomParseWarning.position` still carries no frame beyond its `deflated` flag, and `Element.byteOffset` carries none at all: both are pre-existing and neither is closed here. On every fatal but one the snippet is raw input, cut in the frame that offset is counted in: treat it as PHI and redact it at your own boundary. The exception is `UNSUPPORTED_TRANSFER_SYNTAX`, where the slot carries PS3.6's own name for the unsupported UID (`"RLE Lossless"`) when the registry publishes one, and 16 raw bytes only when it does not. That is deliberate, it predates the frame, and it is named here rather than left to a universal that would be false on the first code a compressed object reaches.
|
|
342
344
|
|
|
343
345
|
```ts
|
|
344
346
|
import { parseDicom, DicomParseError, FATAL_CODES } from "@cosyte/dicom";
|