fix(artifacts): bound expanded ASAR listing before allocation (#2724)
Squash merge of https://github.com/morluto/rea/pull/2724. Co-authored-by: chAngE <172472630+chAng-L19@users.noreply.github.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
This commit is contained in:
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
/** Serialize a header-only ASAR, including Chromium pickle alignment. */
|
||||
export const asarHeaderBytes = (json: string): Buffer => {
|
||||
const text = Buffer.from(json);
|
||||
const headerSize = 8 + Math.ceil(text.length / 4) * 4;
|
||||
const bytes = Buffer.alloc(8 + headerSize);
|
||||
bytes.writeUInt32LE(4, 0);
|
||||
bytes.writeUInt32LE(headerSize, 4);
|
||||
bytes.writeUInt32LE(headerSize - 4, 8);
|
||||
bytes.writeUInt32LE(text.length, 12);
|
||||
text.copy(bytes, 16);
|
||||
return bytes;
|
||||
};
|
||||
|
||||
/** Nested metadata without a recursive fixture builder or real directories. */
|
||||
export const nestedAsarHeader = (
|
||||
depth: number,
|
||||
name: string,
|
||||
leaves: number,
|
||||
): Buffer => {
|
||||
let json = `{"files":{${Array.from(
|
||||
{ length: leaves },
|
||||
(_, index) => `"f${index}":{"size":0,"offset":"0"}`,
|
||||
).join(",")}}}`;
|
||||
for (let index = 0; index < depth; index++)
|
||||
json = `{"files":{${JSON.stringify(name)}:${json}}}`;
|
||||
return asarHeaderBytes(json);
|
||||
};
|
||||
Reference in New Issue
Block a user