@@ -6,6 +6,7 @@ import * as tar from "tar";
|
6 | 6 | import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; |
7 | 7 | import { createSuiteTempRootTracker } from "../test-helpers/temp-dir.js"; |
8 | 8 | import { withRealpathSymlinkRebindRace } from "../test-utils/symlink-rebind-race.js"; |
| 9 | +import { createZipCentralDirectoryArchive } from "../test-utils/zip-central-directory-fixture.js"; |
9 | 10 | import type { ArchiveSecurityError } from "./archive.js"; |
10 | 11 | import { |
11 | 12 | extractArchive, |
@@ -91,31 +92,6 @@ async function expectExtractedSizeBudgetExceeded(params: {
|
91 | 92 | ).rejects.toThrow("archive extracted size exceeds limit"); |
92 | 93 | } |
93 | 94 | |
94 | | -function createZipCentralDirectoryArchive(params: { |
95 | | -actualEntryCount: number; |
96 | | -declaredEntryCount?: number; |
97 | | -declaredCentralDirectorySize?: number; |
98 | | -}): Buffer { |
99 | | -const centralDirectory = Buffer.concat( |
100 | | -Array.from({ length: params.actualEntryCount }, (_, index) => { |
101 | | -const name = Buffer.from(`file-${index}.txt`); |
102 | | -const header = Buffer.alloc(46 + name.byteLength); |
103 | | -header.writeUInt32LE(0x02014b50, 0); |
104 | | -header.writeUInt16LE(name.byteLength, 28); |
105 | | -name.copy(header, 46); |
106 | | -return header; |
107 | | -}), |
108 | | -); |
109 | | -const declaredEntryCount = params.declaredEntryCount ?? params.actualEntryCount; |
110 | | -const eocd = Buffer.alloc(22); |
111 | | -eocd.writeUInt32LE(0x06054b50, 0); |
112 | | -eocd.writeUInt16LE(Math.min(declaredEntryCount, 0xffff), 8); |
113 | | -eocd.writeUInt16LE(Math.min(declaredEntryCount, 0xffff), 10); |
114 | | -eocd.writeUInt32LE(params.declaredCentralDirectorySize ?? centralDirectory.byteLength, 12); |
115 | | -eocd.writeUInt32LE(0, 16); |
116 | | -return Buffer.concat([centralDirectory, eocd]); |
117 | | -} |
118 | | - |
119 | 95 | beforeAll(async () => { |
120 | 96 | await fixtureRootTracker.setup(); |
121 | 97 | }); |
|