dcmjs 0.52.1 → 0.52.2

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/build/dcmjs.es.js CHANGED
@@ -8140,7 +8140,14 @@ var SplitDataView = /*#__PURE__*/function () {
8140
8140
  value: function slice() {
8141
8141
  var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
8142
8142
  var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.size;
8143
- if (start === end) {
8143
+ // Clamp to the data actually held, the way ArrayBuffer.prototype.slice
8144
+ // does. Otherwise a value length declared by a malformed file
8145
+ // allocates the declared size however few bytes are really present.
8146
+ // https://github.com/dcmjs-org/dcmjs/security/advisories/GHSA-xwvm-687g-rm36
8147
+ if (end > this.byteLength) {
8148
+ end = this.byteLength;
8149
+ }
8150
+ if (end <= start) {
8144
8151
  return new Uint8Array(0).buffer;
8145
8152
  }
8146
8153
  var index = this.findStart(start);
@@ -10224,6 +10231,15 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation3) {
10224
10231
  } else if (this.type == 'OB') {
10225
10232
  bytes = stream.readUint8Array(length);
10226
10233
  }*/
10234
+ // A declared value length longer than the data present means a
10235
+ // truncated or malformed file, so read what is there rather than
10236
+ // allocating the declared length, which the file controls.
10237
+ // https://github.com/dcmjs-org/dcmjs/security/advisories/GHSA-xwvm-687g-rm36
10238
+ var available = stream.endOffset - stream.offset;
10239
+ if (length > available) {
10240
+ validationLog.warn("".concat(this.type, " value declares ").concat(length, " bytes but only ").concat(available, " are available - reading the available bytes"));
10241
+ length = available;
10242
+ }
10227
10243
  bytes = stream.getBuffer(stream.offset, stream.offset + length);
10228
10244
  stream.increment(length);
10229
10245
  return [bytes];