qvdjs 0.10.0 → 0.10.1

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/dist/index.js CHANGED
@@ -945,6 +945,24 @@ var init_memoryUtils = __esm({
945
945
  });
946
946
 
947
947
  // src/util/validationUtils.js
948
+ function validateHeaderStructure(headerObj, filePath, stage) {
949
+ const tableHeader = headerObj?.["QvdTableHeader"];
950
+ if (tableHeader === null || typeof tableHeader !== "object" || Array.isArray(tableHeader)) {
951
+ throw new QvdCorruptedError("The XML header contains no usable QvdTableHeader element", {
952
+ rootElements: headerObj && typeof headerObj === "object" ? Object.keys(headerObj) : [],
953
+ file: filePath,
954
+ stage
955
+ });
956
+ }
957
+ const symbolTableLength = parseInt(tableHeader["Offset"], 10);
958
+ if (isNaN(symbolTableLength) || !Number.isSafeInteger(symbolTableLength) || symbolTableLength < 0) {
959
+ throw new QvdCorruptedError("Invalid symbol table offset", {
960
+ offset: tableHeader["Offset"],
961
+ file: filePath,
962
+ stage
963
+ });
964
+ }
965
+ }
948
966
  function validateSymbolTableSizeEarly(symbolTableLength, filePath) {
949
967
  const heapLimit = getHeapLimit();
950
968
  const MAX_SYMBOL_TABLE_SIZE = heapLimit * 0.125;
@@ -1849,6 +1867,7 @@ var init_QvdFileReader = __esm({
1849
1867
  stage: "readData"
1850
1868
  });
1851
1869
  }
1870
+ validateHeaderStructure(headerObj, this._path, "readData");
1852
1871
  const symbolTableOffset = headerEndIndex;
1853
1872
  const symbolTableLength = parseInt(headerObj["QvdTableHeader"]["Offset"], 10);
1854
1873
  const indexTableOffset = symbolTableOffset + symbolTableLength;
@@ -1972,14 +1991,26 @@ var init_QvdFileReader = __esm({
1972
1991
  stage: "parseHeader"
1973
1992
  });
1974
1993
  }
1994
+ validateHeaderStructure(this._header, this._path, "parseHeader");
1975
1995
  const fields = this._header["QvdTableHeader"]?.["Fields"]?.["QvdFieldHeader"];
1976
- const fieldCount = fields === void 0 || fields === null ? 0 : Array.isArray(fields) ? fields.length : 1;
1977
- if (fieldCount === 0) {
1996
+ const fieldList = fields === void 0 || fields === null ? [] : Array.isArray(fields) ? fields : [fields];
1997
+ if (fieldList.length === 0) {
1978
1998
  throw new QvdCorruptedError("The QVD file header declares no fields", {
1979
1999
  file: this._path,
1980
2000
  stage: "parseHeader"
1981
2001
  });
1982
2002
  }
2003
+ const malformedIndex = fieldList.findIndex(
2004
+ (field) => field === null || typeof field !== "object" || Array.isArray(field)
2005
+ );
2006
+ if (malformedIndex !== -1) {
2007
+ throw new QvdCorruptedError("The QVD file header declares a field with no properties", {
2008
+ fieldIndex: malformedIndex,
2009
+ fieldCount: fieldList.length,
2010
+ file: this._path,
2011
+ stage: "parseHeader"
2012
+ });
2013
+ }
1983
2014
  this._headerOffset = headerBeginIndex;
1984
2015
  this._symbolTableOffset = headerEndIndex;
1985
2016
  this._indexTableOffset = this._symbolTableOffset + parseInt(this._header["QvdTableHeader"]["Offset"], 10);