officeparser 7.2.2 → 7.3.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.
- package/README.md +161 -17
- package/dist/OfficeGenerator.js +4 -0
- package/dist/OfficeParser.d.ts +2 -0
- package/dist/OfficeParser.js +6 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +3 -2
- package/dist/defaults.js +3 -3
- package/dist/generators/BaseGenerator.d.ts +11 -0
- package/dist/generators/BaseGenerator.js +29 -0
- package/dist/generators/CsvGenerator.d.ts +9 -1
- package/dist/generators/CsvGenerator.js +24 -14
- package/dist/generators/EpubGenerator.d.ts +18 -0
- package/dist/generators/EpubGenerator.js +242 -0
- package/dist/generators/HtmlGenerator.d.ts +12 -0
- package/dist/generators/HtmlGenerator.js +266 -51
- package/dist/generators/MarkdownGenerator.d.ts +16 -0
- package/dist/generators/MarkdownGenerator.js +173 -24
- package/dist/generators/PdfGenerator.js +32 -0
- package/dist/generators/RtfGenerator.js +12 -15
- package/dist/generators/TextGenerator.js +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/officeparser.browser.d.ts +144 -7
- package/dist/officeparser.browser.iife.js +289 -193
- package/dist/officeparser.browser.mjs +289 -193
- package/dist/officeparser.browser.slim.d.ts +2129 -0
- package/dist/officeparser.browser.slim.iife.js +1278 -0
- package/dist/officeparser.browser.slim.mjs +1277 -0
- package/dist/parsers/EpubParser.d.ts +8 -0
- package/dist/parsers/EpubParser.js +217 -0
- package/dist/parsers/HtmlParser.js +284 -20
- package/dist/parsers/MarkdownParser.js +424 -33
- package/dist/parsers/OpenOfficeParser.js +241 -54
- package/dist/parsers/PdfParser.js +4 -1
- package/dist/parsers/WordParser.js +2 -2
- package/dist/sbom.cdx.json +111 -223
- package/dist/types.d.ts +146 -7
- package/dist/types.js +2 -0
- package/dist/utils/errorUtils.js +3 -2
- package/dist/utils/sanitize.d.ts +99 -0
- package/dist/utils/sanitize.js +228 -0
- package/dist/utils/zipUtils.js +76 -26
- package/package.json +19 -10
package/dist/utils/zipUtils.js
CHANGED
|
@@ -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
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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 (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return false;
|
|
119
|
+
if (final) {
|
|
120
|
+
results.push({ path: name, content: Buffer.concat(chunks) });
|
|
121
|
+
pendingFiles--;
|
|
122
|
+
maybeResolve();
|
|
90
123
|
}
|
|
91
|
-
|
|
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.
|
|
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.3.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",
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"browser": "./dist/officeparser.browser.mjs",
|
|
14
14
|
"import": "./dist/index.mjs",
|
|
15
15
|
"require": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./slim": {
|
|
18
|
+
"types": "./dist/officeparser.browser.slim.d.ts",
|
|
19
|
+
"browser": "./dist/officeparser.browser.slim.mjs",
|
|
20
|
+
"import": "./dist/officeparser.browser.slim.mjs"
|
|
16
21
|
}
|
|
17
22
|
},
|
|
18
23
|
"sideEffects": false,
|
|
@@ -26,12 +31,14 @@
|
|
|
26
31
|
"build": "npm run sync:versions && npm run build:node && npm run build:esm-wrapper && npm run build:browser:types && npm run build:browser",
|
|
27
32
|
"build:node": "tsc",
|
|
28
33
|
"build:esm-wrapper": "node scripts/generate-esm-wrapper.js",
|
|
29
|
-
"build:browser:types": "dts-bundle-generator --no-check -o dist/officeparser.browser.d.ts src/index.ts",
|
|
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",
|
|
30
35
|
"build:browser": "node build_browser.js && npm run sync:docs",
|
|
31
36
|
"sync:versions": "node scripts/sync-pdfjs-versions.js",
|
|
32
|
-
"sync:docs": "mkdir -p docs/dist && cp dist/officeparser.browser.iife.js docs/dist/ && cp dist/officeparser.browser.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/",
|
|
33
38
|
"lint": "eslint src",
|
|
34
|
-
"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",
|
|
35
42
|
"test:baseline": "npm run test:parser:baseline && npm run test:generator:baseline",
|
|
36
43
|
"test:parser": "npx tsx test/parser/testOfficeParser.ts",
|
|
37
44
|
"test:parser:baseline": "npx tsx test/parser/testOfficeParser.ts baseline",
|
|
@@ -95,7 +102,9 @@
|
|
|
95
102
|
"rag",
|
|
96
103
|
"chunking",
|
|
97
104
|
"markdown",
|
|
98
|
-
"html"
|
|
105
|
+
"html",
|
|
106
|
+
"epub",
|
|
107
|
+
"ebook"
|
|
99
108
|
],
|
|
100
109
|
"author": "Harsh Ankur",
|
|
101
110
|
"license": "MIT",
|
|
@@ -105,9 +114,9 @@
|
|
|
105
114
|
"homepage": "https://officeparser.harshankur.com",
|
|
106
115
|
"dependencies": {
|
|
107
116
|
"@xmldom/xmldom": "^0.9.10",
|
|
108
|
-
"fflate": "^0.8.
|
|
117
|
+
"fflate": "^0.8.3",
|
|
109
118
|
"file-type": "^22.0.1",
|
|
110
|
-
"pdfjs-dist": "
|
|
119
|
+
"pdfjs-dist": "6.1.200",
|
|
111
120
|
"tesseract.js": "^7.0.0"
|
|
112
121
|
},
|
|
113
122
|
"peerDependenciesMeta": {
|
|
@@ -121,8 +130,8 @@
|
|
|
121
130
|
"@typescript-eslint/parser": "^8.59.3",
|
|
122
131
|
"buffer": "^6.0.3",
|
|
123
132
|
"dts-bundle-generator": "^9.5.1",
|
|
124
|
-
"esbuild": "^0.
|
|
125
|
-
"esbuild-plugins-node-modules-polyfill": "^1.8.
|
|
133
|
+
"esbuild": "^0.28.1",
|
|
134
|
+
"esbuild-plugins-node-modules-polyfill": "^1.8.2",
|
|
126
135
|
"eslint": "^10.3.0",
|
|
127
136
|
"husky": "^9.1.7",
|
|
128
137
|
"postject": "^1.0.0-alpha.6",
|