@@ -38581,6 +38581,7 @@ const b4a = __nccwpck_require__(3057)
3858138581const headers = __nccwpck_require__(8428)
3858238582
3858338583const EMPTY = b4a.alloc(0)
38584+ const MAX_HEADER_SIZE = 4 * 1024 * 1024 // arbitrary big number
3858438585
3858538586class BufferList {
3858638587 constructor () {
@@ -38597,7 +38598,7 @@ class BufferList {
3859738598 }
3859838599
3859938600 shiftFirst (size) {
38600- return this._buffered === 0 ? null : this._next(size)
38601+ return this.buffered === 0 ? null : this._next(size)
3860138602 }
3860238603
3860338604 shift (size) {
@@ -38726,19 +38727,30 @@ class Extract extends Writable {
3872638727
3872738728 if (!this._header) return true
3872838729
38730+ this._header.byteOffset = this._buffer.shifted
38731+
3872938732 switch (this._header.type) {
3873038733 case 'gnu-long-path':
3873138734 case 'gnu-long-link-path':
3873238735 case 'pax-global-header':
3873338736 case 'pax-header':
3873438737 this._longHeader = true
3873538738 this._missing = this._header.size
38739+ if (this._missing > MAX_HEADER_SIZE) {
38740+ this._continueWrite(new Error('Header exceeds max size'))
38741+ return false
38742+ }
3873638743 return true
3873738744 }
3873838745
3873938746 this._locked = true
3874038747 this._applyLongHeaders()
3874138748
38749+ if (!(this._header.size >= 0)) {
38750+ this._continueWrite(new Error('Invalid header'))
38751+ return false
38752+ }
38753+
3874238754 if (this._header.size === 0 || this._header.type === 'directory') {
3874338755 this.emit('entry', this._header, this._createStream(), this._unlockBound)
3874438756 return true
@@ -39127,6 +39139,7 @@ exports.decode = function decode (buf, filenameEncoding, allowUnknownFormat) {
3912739139 uid,
3912839140 gid,
3912939141 size,
39142+ byteOffset: 0,
3913039143 mtime: new Date(1000 * mtime),
3913139144 type,
3913239145 linkname,
@@ -95820,7 +95833,7 @@ function extractNamespace(rawTagName) {
9582095833}
9582195834
9582295835class OrderedObjParser {
95823- constructor(options) {
95836+ constructor(options, externalEntities ) {
9582495837 this.options = options;
9582595838 this.currentNode = null;
9582695839 this.tagsNodeStack = [];
@@ -95843,7 +95856,7 @@ class OrderedObjParser {
9584395856 if (typeof this.options.htmlEntities === "object") namedEntities = this.options.htmlEntities;
9584495857 else if (this.options.htmlEntities === true) namedEntities = { ...COMMON_HTML, ...CURRENCY };
9584595858 this.entityDecoder = new EntityDecoder({
95846- namedEntities: namedEntities,
95859+ namedEntities: { ... namedEntities, ...externalEntities } ,
9584795860 numericAllowed: this.options.htmlEntities,
9584895861 limit: {
9584995862 maxTotalExpansions: this.options.processEntities.maxTotalExpansions,
@@ -96020,7 +96033,7 @@ function buildAttributesMap(attrStr, jPath, tagName, force = false) {
9602096033
9602196034 if (!hasAttrs) return;
9602296035
96023- if (options.attributesGroupName) {
96036+ if (options.attributesGroupName && !options.preserveOrder ) {
9602496037 const attrCollection = {};
9602596038 attrCollection[options.attributesGroupName] = attrs;
9602696039 return attrCollection;
@@ -96406,12 +96419,16 @@ function isItStopNode() {
9640696419 * @returns
9640796420 */
9640896421function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
96422+ //TODO: ignore boolean attributes in tag expression
96423+ //TODO: if ignore attributes, dont read full attribute expression but the end. But read for xml declaration
9640996424 let attrBoundary = 0;
96410- const chars = [];
9641196425 const len = xmlData.length;
9641296426 const closeCode0 = closingChar.charCodeAt(0);
9641396427 const closeCode1 = closingChar.length > 1 ? closingChar.charCodeAt(1) : -1;
9641496428
96429+ let result = '';
96430+ let segmentStart = i;
96431+
9641596432 for (let index = i; index < len; index++) {
9641696433 const code = xmlData.charCodeAt(index);
9641796434
@@ -96422,17 +96439,18 @@ function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
9642296439 } else if (code === closeCode0) {
9642396440 if (closeCode1 !== -1) {
9642496441 if (xmlData.charCodeAt(index + 1) === closeCode1) {
96425- return { data: String.fromCharCode(...chars), index };
96442+ result += xmlData.substring(segmentStart, index);
96443+ return { data: result, index };
9642696444 }
9642796445 } else {
96428- return { data: String.fromCharCode(...chars), index };
96446+ result += xmlData.substring(segmentStart, index);
96447+ return { data: result, index };
9642996448 }
96430- } else if (code === 9) { // \t
96431- chars.push(32); // space
96432- continue;
96449+ } else if (code === 9 && !attrBoundary) { // \t - only replace with space outside attribute values
96450+ // Flush accumulated segment, add space, start new segment
96451+ result += xmlData.substring(segmentStart, index) + ' ';
96452+ segmentStart = index + 1;
9643396453 }
96434-
96435- chars.push(code);
9643696454 }
9643796455}
9643896456
@@ -96792,8 +96810,8 @@ class XMLParser {
9679296810 throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`)
9679396811 }
9679496812 }
96795- const orderedObjParser = new OrderedObjParser(this.options);
96796- orderedObjParser.entityDecoder.setExternalEntities(this.externalEntities);
96813+ const orderedObjParser = new OrderedObjParser(this.options, this.externalEntities );
96814+ // orderedObjParser.entityDecoder.setExternalEntities(this.externalEntities);
9679796815 const orderedResult = orderedObjParser.parseXml(xmlData);
9679896816 if (this.options.preserveOrder || orderedResult === undefined) return orderedResult;
9679996817 else return prettify(orderedResult, this.options, orderedObjParser.matcher, orderedObjParser.readonlyMatcher);
0 commit comments