onionskin-cli 0.0.5 → 0.0.6
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/CHANGELOG.md +98 -0
- package/README.md +4 -4
- package/package.json +1 -1
- package/scripts/checker/check.py +24 -5
- package/scripts/checker/requirements.txt +482 -5
- package/scripts/requirements.txt +482 -5
- package/scripts/rewriter/apple/main.swift +1 -1
- package/scripts/rewriter/apple/onionskin-fm +0 -0
- package/scripts/rewriter/apple/onionskin-fm.json +1 -1
- package/skills/onionskin/SKILL.md +4 -4
- package/skills/onionskin/reference/ops.md +1 -1
- package/src/agent-runner.js +94 -15
- package/src/checker.js +238 -33
- package/src/cli.js +173 -33
- package/src/doctor.js +12 -3
- package/src/docx.js +130 -63
- package/src/fsutil.js +13 -5
- package/src/history.js +11 -2
- package/src/html-render.js +74 -15
- package/src/html-utf8.js +1 -1
- package/src/html.js +3 -1
- package/src/merge-package.js +82 -26
- package/src/offload.js +25 -6
- package/src/ops/docx-table.js +5 -3
- package/src/ops/pptx.js +8 -2
- package/src/ops/xlsx.js +114 -8
- package/src/package.js +17 -2
- package/src/pptx.js +244 -8
- package/src/question.js +10 -3
- package/src/quick.js +1 -1
- package/src/redline-check.js +12 -2
- package/src/rewriter.js +38 -8
- package/src/server-entry.js +4 -3
- package/src/server.js +97 -28
- package/src/session.js +13 -2
- package/src/setup.js +20 -2
- package/src/update.js +248 -19
- package/src/voice-guide.js +12 -7
- package/src/voice-learn.js +11 -1
- package/src/voice-store.js +11 -4
- package/src/voice.js +2 -1
- package/src/xlsx.js +25 -5
- package/src/zip-write.js +8 -4
- package/src/zip.js +64 -13
- package/web/dist/assets/{index-DytKkMdi.js → index-CjsTf5gj.js} +108 -106
- package/web/dist/assets/index-DnbLtHhG.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-DkNx0LSH.css +0 -1
package/src/zip.js
CHANGED
|
@@ -11,17 +11,64 @@ export class ZipError extends Error {}
|
|
|
11
11
|
const MB = (n) => (n >= 1024 * 1024 ? `${Math.round(n / 1024 / 1024)} MB` : `${n.toLocaleString("en-US")} bytes`);
|
|
12
12
|
const SPLIT = "Split it into smaller files, or save it again in Word, Excel or PowerPoint, and open that";
|
|
13
13
|
|
|
14
|
+
const CRC_TABLE = (() => {
|
|
15
|
+
const t = new Uint32Array(256);
|
|
16
|
+
for (let i = 0; i < 256; i++) {
|
|
17
|
+
let c = i;
|
|
18
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
19
|
+
t[i] = c >>> 0;
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
})();
|
|
23
|
+
export function crc32Pure(buf) {
|
|
24
|
+
let c = 0xffffffff;
|
|
25
|
+
for (let i = 0; i < buf.length; i++) c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
|
|
26
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
27
|
+
}
|
|
28
|
+
export function crc32(buf) {
|
|
29
|
+
return typeof zlib.crc32 === "function" ? zlib.crc32(buf) >>> 0 : crc32Pure(buf);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function validEocd(buf, i) {
|
|
33
|
+
const count = buf.readUInt16LE(i + 10);
|
|
34
|
+
const cdSize = buf.readUInt32LE(i + 12);
|
|
35
|
+
const cdOffset = buf.readUInt32LE(i + 16);
|
|
36
|
+
if (count === 0xffff || cdSize === 0xffffffff || cdOffset === 0xffffffff) return false;
|
|
37
|
+
if (count > MAX_ENTRIES) return false;
|
|
38
|
+
if (cdOffset + cdSize !== i) return false;
|
|
39
|
+
let p = cdOffset;
|
|
40
|
+
for (let k = 0; k < count; k++) {
|
|
41
|
+
if (p + 46 > i || buf.readUInt32LE(p) !== 0x02014b50) return false;
|
|
42
|
+
const nameLen = buf.readUInt16LE(p + 28);
|
|
43
|
+
const extraLen = buf.readUInt16LE(p + 30);
|
|
44
|
+
const commentLen = buf.readUInt16LE(p + 32);
|
|
45
|
+
if (p + 46 + nameLen + extraLen + commentLen > i) return false;
|
|
46
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
47
|
+
}
|
|
48
|
+
return p === i;
|
|
49
|
+
}
|
|
50
|
+
|
|
14
51
|
/** Reads the central directory of a ZIP held in memory. No ZIP64 (files over 4 GB are refused). */
|
|
15
52
|
export function openZip(buf, { budget = MAX_TOTAL_EXPANSION } = {}) {
|
|
16
53
|
if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
|
|
17
54
|
if (buf.length < 22 || buf.readUInt32LE(0) !== 0x04034b50) throw new ZipError("not a ZIP file");
|
|
18
|
-
let
|
|
55
|
+
let exactValid = -1;
|
|
56
|
+
let exactInvalid = -1;
|
|
57
|
+
let fallback = -1;
|
|
19
58
|
for (let i = buf.length - 22; i >= Math.max(0, buf.length - 22 - 65535); i--) {
|
|
20
|
-
if (buf.readUInt32LE(i)
|
|
21
|
-
|
|
22
|
-
|
|
59
|
+
if (buf.readUInt32LE(i) !== 0x06054b50) continue;
|
|
60
|
+
const end = i + 22 + buf.readUInt16LE(i + 20);
|
|
61
|
+
if (end === buf.length) {
|
|
62
|
+
if (validEocd(buf, i)) {
|
|
63
|
+
exactValid = i;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (exactInvalid < 0) exactInvalid = i;
|
|
67
|
+
} else if (end < buf.length && validEocd(buf, i)) {
|
|
68
|
+
fallback = i;
|
|
23
69
|
}
|
|
24
70
|
}
|
|
71
|
+
const eocd = exactValid >= 0 ? exactValid : fallback >= 0 ? fallback : exactInvalid;
|
|
25
72
|
if (eocd < 0) throw new ZipError("ZIP end record not found");
|
|
26
73
|
const count = buf.readUInt16LE(eocd + 10);
|
|
27
74
|
const cdSize = buf.readUInt32LE(eocd + 12);
|
|
@@ -32,7 +79,7 @@ export function openZip(buf, { budget = MAX_TOTAL_EXPANSION } = {}) {
|
|
|
32
79
|
const entries = new Map();
|
|
33
80
|
let p = cdOffset;
|
|
34
81
|
for (let k = 0; k < count; k++) {
|
|
35
|
-
if (p + 46 >
|
|
82
|
+
if (p + 46 > cdOffset + cdSize || buf.readUInt32LE(p) !== 0x02014b50) throw new ZipError("bad ZIP central directory");
|
|
36
83
|
const flags = buf.readUInt16LE(p + 8);
|
|
37
84
|
const method = buf.readUInt16LE(p + 10);
|
|
38
85
|
const crc = buf.readUInt32LE(p + 16);
|
|
@@ -42,6 +89,8 @@ export function openZip(buf, { budget = MAX_TOTAL_EXPANSION } = {}) {
|
|
|
42
89
|
const extraLen = buf.readUInt16LE(p + 30);
|
|
43
90
|
const commentLen = buf.readUInt16LE(p + 32);
|
|
44
91
|
const localOffset = buf.readUInt32LE(p + 42);
|
|
92
|
+
if (p + 46 + nameLen + extraLen + commentLen > cdOffset + cdSize) throw new ZipError("bad ZIP central directory");
|
|
93
|
+
if (compSize === 0xffffffff || size === 0xffffffff || localOffset === 0xffffffff) throw new ZipError("ZIP64 is not supported");
|
|
45
94
|
const name = buf.toString("utf8", p + 46, p + 46 + nameLen);
|
|
46
95
|
if (name.startsWith("/") || name.split("/").includes("..") || name.includes("\\") || name.includes("\0")) throw new ZipError(`unsafe ZIP entry name: ${JSON.stringify(name)}`);
|
|
47
96
|
if (entries.has(name)) throw new ZipError(`duplicate ZIP entry: ${JSON.stringify(name)}`);
|
|
@@ -67,26 +116,28 @@ export function openZip(buf, { budget = MAX_TOTAL_EXPANSION } = {}) {
|
|
|
67
116
|
function read(name, cap = MAX_XML_BYTES) {
|
|
68
117
|
const e = entries.get(name);
|
|
69
118
|
if (!e) return null;
|
|
119
|
+
if (e.flags & 0x1) throw new ZipError(`encrypted ZIP entry ${JSON.stringify(name)}`);
|
|
70
120
|
cap = Math.min(cap, MAX_ENTRY_BYTES);
|
|
71
121
|
const data = raw(name);
|
|
122
|
+
let out;
|
|
72
123
|
if (e.method === 0) {
|
|
73
124
|
// a stored entry is bounded by the same per-entry cap as an inflated one
|
|
74
125
|
if (data.length > cap) throw new ZipError(`a part of this file (${JSON.stringify(name)}) is larger than ${MB(cap)} unpacked, more than Onionskin can read. ${SPLIT}`);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (e.method === 8) {
|
|
79
|
-
let out;
|
|
126
|
+
out = Buffer.from(data);
|
|
127
|
+
} else if (e.method === 8) {
|
|
80
128
|
try {
|
|
81
129
|
out = gated(() => zlib.inflateRawSync(data, { maxOutputLength: cap })); // never stopped inside zlib (src/stop-gate.js)
|
|
82
130
|
} catch (err) {
|
|
83
131
|
if (err?.code === "ERR_BUFFER_TOO_LARGE") throw new ZipError(`a part of this file (${JSON.stringify(name)}) is larger than ${MB(cap)} unpacked, more than Onionskin can read. ${SPLIT}`);
|
|
84
132
|
throw new ZipError(`cannot inflate ${JSON.stringify(name)}: ${err.message}`);
|
|
85
133
|
}
|
|
86
|
-
|
|
87
|
-
|
|
134
|
+
} else {
|
|
135
|
+
throw new ZipError(`unsupported ZIP method ${e.method} for ${JSON.stringify(name)}`);
|
|
88
136
|
}
|
|
89
|
-
throw new ZipError(`
|
|
137
|
+
if (out.length !== e.size) throw new ZipError(`size mismatch for ${JSON.stringify(name)}`);
|
|
138
|
+
if (crc32(out) !== e.crc) throw new ZipError(`CRC mismatch for ${JSON.stringify(name)} (does not match its stored checksum)`);
|
|
139
|
+
spend(name, out.length);
|
|
140
|
+
return out;
|
|
90
141
|
}
|
|
91
142
|
return { names: [...entries.keys()], entries, read, raw, buf, eocd, readText: (name, cap) => read(name, cap)?.toString("utf8") ?? null };
|
|
92
143
|
}
|