officeparser 7.2.3 → 7.4.0

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.
Files changed (49) hide show
  1. package/README.md +277 -17
  2. package/dist/OfficeConverter.d.ts +1 -1
  3. package/dist/OfficeConverter.js +3 -0
  4. package/dist/OfficeGenerator.js +4 -0
  5. package/dist/OfficeParser.d.ts +2 -0
  6. package/dist/OfficeParser.js +6 -0
  7. package/dist/cli.d.ts +1 -1
  8. package/dist/cli.js +5 -2
  9. package/dist/defaults.js +12 -0
  10. package/dist/generators/BaseGenerator.d.ts +34 -1
  11. package/dist/generators/BaseGenerator.js +98 -0
  12. package/dist/generators/CsvGenerator.d.ts +9 -1
  13. package/dist/generators/CsvGenerator.js +28 -16
  14. package/dist/generators/EpubGenerator.d.ts +43 -0
  15. package/dist/generators/EpubGenerator.js +312 -0
  16. package/dist/generators/HtmlGenerator.d.ts +12 -0
  17. package/dist/generators/HtmlGenerator.js +378 -61
  18. package/dist/generators/MarkdownGenerator.d.ts +28 -5
  19. package/dist/generators/MarkdownGenerator.js +432 -51
  20. package/dist/generators/PdfGenerator.js +32 -0
  21. package/dist/generators/RtfGenerator.js +47 -22
  22. package/dist/generators/TextGenerator.js +98 -11
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/officeparser.browser.d.ts +427 -20
  26. package/dist/officeparser.browser.iife.js +338 -206
  27. package/dist/officeparser.browser.mjs +346 -214
  28. package/dist/officeparser.browser.slim.d.ts +427 -20
  29. package/dist/officeparser.browser.slim.iife.js +346 -214
  30. package/dist/officeparser.browser.slim.mjs +346 -214
  31. package/dist/parsers/EpubParser.d.ts +8 -0
  32. package/dist/parsers/EpubParser.js +217 -0
  33. package/dist/parsers/ExcelParser.js +2 -0
  34. package/dist/parsers/HtmlParser.js +507 -48
  35. package/dist/parsers/MarkdownParser.js +704 -92
  36. package/dist/parsers/OpenOfficeParser.js +128 -20
  37. package/dist/parsers/PdfParser.js +4 -1
  38. package/dist/parsers/PowerPointParser.js +1 -0
  39. package/dist/parsers/WordParser.js +1 -0
  40. package/dist/sbom.cdx.json +1695 -0
  41. package/dist/types.d.ts +427 -20
  42. package/dist/types.js +8 -0
  43. package/dist/utils/configUtils.js +53 -4
  44. package/dist/utils/errorUtils.js +7 -3
  45. package/dist/utils/sanitize.d.ts +139 -0
  46. package/dist/utils/sanitize.js +318 -0
  47. package/dist/utils/xmlUtils.js +2 -2
  48. package/dist/utils/zipUtils.js +76 -26
  49. package/package.json +16 -12
@@ -66,38 +66,88 @@ const extractFiles = (zipInput, filterFn, limits) => {
66
66
  ? limits.maxZipEntries
67
67
  : 10000;
68
68
  return new Promise((resolve, reject) => {
69
+ // Decompress as a stream and cap on the ACTUAL inflated byte count rather than
70
+ // the size declared in the ZIP header. The declared size is attacker-controlled,
71
+ // so a "zip bomb" can understate it and still inflate to gigabytes; counting real
72
+ // output bytes and aborting once the limit is crossed is the only reliable guard.
73
+ const results = [];
69
74
  let totalEntryCount = 0;
70
- let entryCount = 0;
71
- let declaredTotal = 0;
72
- (0, fflate_1.unzip)(new Uint8Array(zipInput.buffer, zipInput.byteOffset, zipInput.byteLength), {
73
- filter: (file) => {
74
- totalEntryCount++;
75
- if (totalEntryCount > maxZipEntries) {
76
- reject((0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.ZIP_ENTRY_COUNT_LIMIT_EXCEEDED, undefined, maxZipEntries));
77
- return false;
75
+ let actualTotalBytes = 0;
76
+ let pendingFiles = 0;
77
+ let pushComplete = false;
78
+ let settled = false;
79
+ const fail = (err) => {
80
+ if (settled)
81
+ return;
82
+ settled = true;
83
+ reject(err);
84
+ };
85
+ const maybeResolve = () => {
86
+ if (!settled && pushComplete && pendingFiles === 0) {
87
+ settled = true;
88
+ resolve(results);
89
+ }
90
+ };
91
+ const unzipper = new fflate_1.Unzip((file) => {
92
+ if (settled)
93
+ return;
94
+ totalEntryCount++;
95
+ if (totalEntryCount > maxZipEntries) {
96
+ fail((0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.ZIP_ENTRY_COUNT_LIMIT_EXCEEDED, undefined, maxZipEntries));
97
+ return;
98
+ }
99
+ if (!filterFn(file.name))
100
+ return;
101
+ const name = file.name;
102
+ const chunks = [];
103
+ pendingFiles++;
104
+ file.ondata = (err, chunk, final) => {
105
+ if (settled)
106
+ return;
107
+ if (err) {
108
+ fail(err);
109
+ return;
78
110
  }
79
- if (!filterFn(file.name))
80
- return false;
81
- if (typeof file.originalSize !== 'number' || !Number.isFinite(file.originalSize) || file.originalSize < 0) {
82
- reject((0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.ZIP_ENTRY_INVALID_SIZE));
83
- return false;
111
+ if (chunk && chunk.length) {
112
+ actualTotalBytes += chunk.length;
113
+ if (actualTotalBytes > maxUncompressedBytes) {
114
+ fail((0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.ZIP_SIZE_LIMIT_EXCEEDED, undefined, maxUncompressedBytes));
115
+ return;
116
+ }
117
+ chunks.push(Buffer.from(chunk));
84
118
  }
85
- entryCount++;
86
- declaredTotal += file.originalSize;
87
- if (declaredTotal > maxUncompressedBytes) {
88
- reject((0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.ZIP_SIZE_LIMIT_EXCEEDED, undefined, maxUncompressedBytes));
89
- return false;
119
+ if (final) {
120
+ results.push({ path: name, content: Buffer.concat(chunks) });
121
+ pendingFiles--;
122
+ maybeResolve();
90
123
  }
91
- return true;
124
+ };
125
+ try {
126
+ file.start();
127
+ }
128
+ catch (e) {
129
+ fail(e);
92
130
  }
93
- }, (err, decompressed) => {
94
- if (err)
95
- return reject(err);
96
- resolve(Object.entries(decompressed).map(([path, data]) => ({
97
- path,
98
- content: Buffer.from(data)
99
- })));
100
131
  });
132
+ unzipper.register(fflate_1.UnzipInflate);
133
+ const src = new Uint8Array(zipInput.buffer, zipInput.byteOffset, zipInput.byteLength);
134
+ // Feed the compressed input in bounded chunks so the actual-size check can abort a
135
+ // bomb early; the worst-case overshoot is one chunk's worth of inflation.
136
+ const PUSH_CHUNK = 1 << 16; // 64 KiB
137
+ try {
138
+ let offset = 0;
139
+ while (offset < src.length && !settled) {
140
+ const end = Math.min(offset + PUSH_CHUNK, src.length);
141
+ unzipper.push(src.subarray(offset, end), end >= src.length);
142
+ offset = end;
143
+ }
144
+ }
145
+ catch (e) {
146
+ fail(e);
147
+ return;
148
+ }
149
+ pushComplete = true;
150
+ maybeResolve();
101
151
  });
102
152
  };
103
153
  exports.extractFiles = extractFiles;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "officeparser",
3
- "version": "7.2.3",
4
- "description": "A robust, strictly-typed Node.js and Browser library for parsing office files (.docx, .pptx, .xlsx, .odt, .odp, .ods, .pdf, .rtf, .csv, .md, .html) and generating high-fidelity outputs in Markdown, HTML, CSV, RTF, and RAG-focused chunks.",
3
+ "version": "7.4.0",
4
+ "description": "A robust, strictly-typed Node.js and Browser library for parsing office files (.docx, .pptx, .xlsx, .odt, .odp, .ods, .pdf, .rtf, .csv, .md, .html, .epub) and generating high-fidelity outputs in Markdown, HTML, CSV, RTF, PDF, EPUB, and RAG-focused chunks.",
5
5
  "funding": "https://github.com/sponsors/harshankur",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -34,9 +34,11 @@
34
34
  "build:browser:types": "dts-bundle-generator --no-check -o dist/officeparser.browser.d.ts src/index.ts && cp dist/officeparser.browser.d.ts dist/officeparser.browser.slim.d.ts",
35
35
  "build:browser": "node build_browser.js && npm run sync:docs",
36
36
  "sync:versions": "node scripts/sync-pdfjs-versions.js",
37
- "sync:docs": "mkdir -p docs/dist && cp dist/officeparser.browser.iife.js docs/dist/ && cp dist/officeparser.browser.mjs docs/dist/ && cp dist/officeparser.browser.slim.iife.js docs/dist/ && cp dist/officeparser.browser.slim.mjs docs/dist/ && mkdir -p docs/test/files && cp test/files/* docs/test/files/",
37
+ "sync:docs": "mkdir -p docs/dist && cp dist/officeparser.browser.iife.js docs/dist/ && cp dist/officeparser.browser.mjs docs/dist/ && cp dist/officeparser.browser.slim.iife.js docs/dist/ && cp dist/officeparser.browser.slim.mjs docs/dist/ && mkdir -p docs/test/files && cp -r test/files/* docs/test/files/",
38
38
  "lint": "eslint src",
39
- "test": "npm run lint && npm run test:clean && npm run build && npm run test:license && npm run test:artifacts && npm run test:parser && npm run test:generator && npm run test:cli",
39
+ "test": "npm run lint && npm run test:clean && npm run build && npm run test:license && npm run test:artifacts && npm run test:parser && npm run test:exhaustive && npm run test:generator && npm run test:security && npm run test:cli",
40
+ "test:exhaustive": "npx tsx test/testExhaustive.ts",
41
+ "test:security": "npx tsx test/security/testSanitization.ts",
40
42
  "test:baseline": "npm run test:parser:baseline && npm run test:generator:baseline",
41
43
  "test:parser": "npx tsx test/parser/testOfficeParser.ts",
42
44
  "test:parser:baseline": "npx tsx test/parser/testOfficeParser.ts baseline",
@@ -100,7 +102,9 @@
100
102
  "rag",
101
103
  "chunking",
102
104
  "markdown",
103
- "html"
105
+ "html",
106
+ "epub",
107
+ "ebook"
104
108
  ],
105
109
  "author": "Harsh Ankur",
106
110
  "license": "MIT",
@@ -121,19 +125,19 @@
121
125
  }
122
126
  },
123
127
  "devDependencies": {
124
- "@types/node": "^25.5.0",
125
- "@typescript-eslint/eslint-plugin": "^8.59.3",
126
- "@typescript-eslint/parser": "^8.59.3",
128
+ "@types/node": "^26.1.1",
129
+ "@typescript-eslint/eslint-plugin": "^8.64.0",
130
+ "@typescript-eslint/parser": "^8.64.0",
127
131
  "buffer": "^6.0.3",
128
132
  "dts-bundle-generator": "^9.5.1",
129
133
  "esbuild": "^0.28.1",
130
134
  "esbuild-plugins-node-modules-polyfill": "^1.8.2",
131
- "eslint": "^10.3.0",
135
+ "eslint": "^10.7.0",
132
136
  "husky": "^9.1.7",
133
137
  "postject": "^1.0.0-alpha.6",
134
138
  "process": "^0.11.10",
135
- "puppeteer": "^22.15.0",
136
- "tsx": "^4.21.0",
137
- "typescript": "^6.0.2"
139
+ "puppeteer": "^24.43.1",
140
+ "tsx": "^4.23.1",
141
+ "typescript": "^6.0.3"
138
142
  }
139
143
  }