1.1.80: 修复 bug,修复稳定性(#168 #169 #170 #172 #176)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-27 23:34:55 +08:00
1 parent 24f4a7f5df
commit 9a8e8481e8
10 files changed
+178 -40

No files matched your search

+11 -3
View File
@@ -73,12 +73,23 @@ function localDataOffset(buf, localOffset) {
return localOffset + 30 + nameLen + extraLen;
}
function isZipDirectoryEntry(name) {
return /[/\\]$/.test(String(name || ""));
}
export function extractZipBuffer(buf, dest) {
fs.mkdirSync(dest, { recursive: true });
const root = path.resolve(dest);
const prefix = root.endsWith(path.sep) ? root : root + path.sep;
for (const entry of readZipEntries(buf)) {
const rel = safeZipName(entry.name);
if (!rel) continue;
const out = path.resolve(root, rel);
if (out !== root && !out.startsWith(prefix)) throw new Error("Invalid zip path");
if (isZipDirectoryEntry(entry.name)) {
fs.mkdirSync(out, { recursive: true });
continue;
}
if (entry.compSize === 0xffffffff || entry.localOffset === 0xffffffff) {
throw new Error("zip64 is not supported");
}
@@ -90,9 +101,6 @@ export function extractZipBuffer(buf, dest) {
if (end > buf.length) throw new Error("Truncated zip data");
const compressed = buf.subarray(start, end);
const body = entry.method === 0 ? compressed : zlib.inflateRawSync(compressed);
const out = path.resolve(root, rel);
const prefix = root.endsWith(path.sep) ? root : root + path.sep;
if (out !== root && !out.startsWith(prefix)) throw new Error("Invalid zip path");
fs.mkdirSync(path.dirname(out), { recursive: true });
fs.writeFileSync(out, body);
}