@cosyte/dicom 0.1.6 → 0.1.7
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 +8 -0
- package/dist/index.cjs +40 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.mjs +40 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d04ae1a: `serializeDicom()` now refuses a Private Creator or File Meta element whose value is over 65,534 bytes with `DicomSerializeError` code `VALUE_TOO_LONG_FOR_VR`, instead of throwing a `RangeError`.
|
|
8
|
+
|
|
9
|
+
PS3.5 section 6.2.2 has a value that long, in a VR with a 16-bit Value Length Field, written as `UN`, which the writer has done since 0.1.5, but forbids `UN` for a Private Creator Data Element (gggg,0010-00FF) and for any File Meta Information element (0002,xxxx). Such a value has no encoding, and the writer still put its length through the 16-bit write. Callers now see a `DicomSerializeError` they can narrow on `err.code === "VALUE_TOO_LONG_FOR_VR"`, with a fixed message that carries no tag, length or byte of the value, and nothing is written. It applies to a Private Creator under the Explicit VR syntaxes (Implicit VR Little Endian has a 32-bit length and writes it) and to a File Meta element under every syntax, since the File Meta group is always Explicit VR Little Endian. `deidentify()` throws the same error when it re-encodes a Sequence Item that keeps such a creator, which only a `RetainSafePrivate` run whose `Profile` names a creator that long does. `SERIALIZE_ERROR_CODES` gains the new code, so an exhaustive `switch` over `SerializeErrorCode` needs one more case.
|
|
10
|
+
|
|
3
11
|
## 0.1.6
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,7 @@ var __export = (target, all) => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = "0.1.
|
|
14
|
+
var VERSION = "0.1.7";
|
|
15
15
|
|
|
16
16
|
// src/dictionary/index.ts
|
|
17
17
|
var dictionary_exports = {};
|
|
@@ -14958,8 +14958,43 @@ function toDate(value, options) {
|
|
|
14958
14958
|
const instant = new Date(utc.getTime() - offsetMinutes * 6e4);
|
|
14959
14959
|
return Number.isNaN(instant.getTime()) ? void 0 : instant;
|
|
14960
14960
|
}
|
|
14961
|
+
|
|
14962
|
+
// src/serialize/errors.ts
|
|
14963
|
+
var SERIALIZE_ERROR_CODES = {
|
|
14964
|
+
MISSING_TRANSFER_SYNTAX: "MISSING_TRANSFER_SYNTAX",
|
|
14965
|
+
UNSUPPORTED_TRANSFER_SYNTAX: "UNSUPPORTED_TRANSFER_SYNTAX",
|
|
14966
|
+
INVALID_ENCAPSULATED_PIXEL_DATA: "INVALID_ENCAPSULATED_PIXEL_DATA",
|
|
14967
|
+
DIRECTORY_OFFSET_UNRESOLVED: "DIRECTORY_OFFSET_UNRESOLVED",
|
|
14968
|
+
DIRECTORY_OFFSET_DEFLATED: "DIRECTORY_OFFSET_DEFLATED",
|
|
14969
|
+
VALUE_TOO_LONG_FOR_VR: "VALUE_TOO_LONG_FOR_VR"
|
|
14970
|
+
};
|
|
14971
|
+
var DicomSerializeError = class extends Error {
|
|
14972
|
+
code;
|
|
14973
|
+
/**
|
|
14974
|
+
* Construct a new `DicomSerializeError`. The `message` MUST be built only
|
|
14975
|
+
* from structural facts (never a decoded attribute value) so the error is
|
|
14976
|
+
* always safe to log.
|
|
14977
|
+
*
|
|
14978
|
+
* @internal
|
|
14979
|
+
*/
|
|
14980
|
+
constructor(code, message) {
|
|
14981
|
+
super(`[${code}] ${message}`);
|
|
14982
|
+
this.name = "DicomSerializeError";
|
|
14983
|
+
this.code = code;
|
|
14984
|
+
}
|
|
14985
|
+
};
|
|
14986
|
+
|
|
14987
|
+
// src/serialize/element.ts
|
|
14961
14988
|
var UNDEFINED_LENGTH4 = 4294967295;
|
|
14962
14989
|
var MAX_SHORT_FORM_LENGTH = 65534;
|
|
14990
|
+
var PRIVATE_CREATOR_TOO_LONG_MESSAGE = "A Private Creator Data Element carries a value longer than 65,534 bytes under an Explicit VR Transfer Syntax, in a VR whose Value Length Field is 16 bits. PS3.5 section 6.2.2 has such a value written with VR UN, but says UN shall not be used for a Private Creator Data Element, so the value has no encoding and nothing is written.";
|
|
14991
|
+
var FILE_META_TOO_LONG_MESSAGE = "A File Meta Information element carries a value longer than 65,534 bytes in a VR whose Explicit VR Value Length Field is 16 bits. PS3.5 section 6.2.2 has such a value written with VR UN, but says UN shall not be used for a File Meta Information element, so the value has no encoding and nothing is written.";
|
|
14992
|
+
function refuseTooLongForVr(kind) {
|
|
14993
|
+
throw new DicomSerializeError(
|
|
14994
|
+
SERIALIZE_ERROR_CODES.VALUE_TOO_LONG_FOR_VR,
|
|
14995
|
+
kind === "privateCreator" ? PRIVATE_CREATOR_TOO_LONG_MESSAGE : FILE_META_TOO_LONG_MESSAGE
|
|
14996
|
+
);
|
|
14997
|
+
}
|
|
14963
14998
|
var NULL_PAD_VRS = /* @__PURE__ */ new Set(["UI", "OB", "OW", "OF", "OD", "OL", "OV", "UN"]);
|
|
14964
14999
|
function padValue(value, vr) {
|
|
14965
15000
|
if (value.length % 2 === 0) return buffer.Buffer.from(value);
|
|
@@ -15022,7 +15057,9 @@ function encodeDatasetElement(el, encoding, rawBytes = el.rawBytes) {
|
|
|
15022
15057
|
value
|
|
15023
15058
|
]);
|
|
15024
15059
|
}
|
|
15025
|
-
if (value.length > MAX_SHORT_FORM_LENGTH
|
|
15060
|
+
if (value.length > MAX_SHORT_FORM_LENGTH) {
|
|
15061
|
+
if (isPrivateCreator(group, element)) refuseTooLongForVr("privateCreator");
|
|
15062
|
+
if (group === 2) refuseTooLongForVr("fileMeta");
|
|
15026
15063
|
return buffer.Buffer.concat([
|
|
15027
15064
|
uint16(group, littleEndian),
|
|
15028
15065
|
uint16(element, littleEndian),
|
|
@@ -15041,30 +15078,6 @@ function encodeDatasetElement(el, encoding, rawBytes = el.rawBytes) {
|
|
|
15041
15078
|
value
|
|
15042
15079
|
]);
|
|
15043
15080
|
}
|
|
15044
|
-
|
|
15045
|
-
// src/serialize/errors.ts
|
|
15046
|
-
var SERIALIZE_ERROR_CODES = {
|
|
15047
|
-
MISSING_TRANSFER_SYNTAX: "MISSING_TRANSFER_SYNTAX",
|
|
15048
|
-
UNSUPPORTED_TRANSFER_SYNTAX: "UNSUPPORTED_TRANSFER_SYNTAX",
|
|
15049
|
-
INVALID_ENCAPSULATED_PIXEL_DATA: "INVALID_ENCAPSULATED_PIXEL_DATA",
|
|
15050
|
-
DIRECTORY_OFFSET_UNRESOLVED: "DIRECTORY_OFFSET_UNRESOLVED",
|
|
15051
|
-
DIRECTORY_OFFSET_DEFLATED: "DIRECTORY_OFFSET_DEFLATED"
|
|
15052
|
-
};
|
|
15053
|
-
var DicomSerializeError = class extends Error {
|
|
15054
|
-
code;
|
|
15055
|
-
/**
|
|
15056
|
-
* Construct a new `DicomSerializeError`. The `message` MUST be built only
|
|
15057
|
-
* from structural facts (never a decoded attribute value) so the error is
|
|
15058
|
-
* always safe to log.
|
|
15059
|
-
*
|
|
15060
|
-
* @internal
|
|
15061
|
-
*/
|
|
15062
|
-
constructor(code, message) {
|
|
15063
|
-
super(`[${code}] ${message}`);
|
|
15064
|
-
this.name = "DicomSerializeError";
|
|
15065
|
-
this.code = code;
|
|
15066
|
-
}
|
|
15067
|
-
};
|
|
15068
15081
|
var UNDEFINED_LENGTH5 = 4294967295;
|
|
15069
15082
|
var ITEM2 = 4294893568;
|
|
15070
15083
|
var ITEM_DELIMITATION = 4294893581;
|
|
@@ -15509,6 +15522,7 @@ function encodeMetaElement(tag, vr, rawValue) {
|
|
|
15509
15522
|
value
|
|
15510
15523
|
]);
|
|
15511
15524
|
}
|
|
15525
|
+
if (value.length > MAX_SHORT_FORM_LENGTH) refuseTooLongForVr("fileMeta");
|
|
15512
15526
|
const lengthBuf = buffer.Buffer.alloc(2);
|
|
15513
15527
|
lengthBuf.writeUInt16LE(value.length, 0);
|
|
15514
15528
|
return buffer.Buffer.concat([groupBuf, elementBuf, vrBuf, lengthBuf, value]);
|