mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
refactor(zip): share local header facts across readers (#12629)
This commit is contained in:
1 parent
e782a6a8cd
commit
fb9f19d83a
4 files changed
+15
-8
No files matched your search
@@ -5,7 +5,6 @@
|
||||
"src/domain/managed/managedMetadataInventoryRows.ts": 2,
|
||||
"src/domain/native/elfPointerRelocations.ts": 6,
|
||||
"src/domain/native/readBinaryContainer.ts": 1,
|
||||
"src/ghidra/extensions/GhidraExtensions.ts": 1,
|
||||
"src/native/AppleDispatchMetadata.ts": 4,
|
||||
"src/native/AppleObjcDispatchFacets.ts": 1,
|
||||
"src/native/AppleSwiftDispatchFacets.ts": 1,
|
||||
|
||||
@@ -23,6 +23,10 @@ import {
|
||||
ZIP_CENTRAL_HEADER,
|
||||
readZipCentralExtent,
|
||||
} from "../zip/zipCentralHeader.js";
|
||||
import {
|
||||
ZIP_LOCAL_HEADER_BYTES,
|
||||
ZIP_LOCAL_HEADER_SIGNATURE,
|
||||
} from "../zip/zipLocalHeader.js";
|
||||
import {
|
||||
canonicalNameHash,
|
||||
compareCanonicalNames,
|
||||
@@ -395,8 +399,6 @@ export const detectV1Signature = (
|
||||
};
|
||||
};
|
||||
|
||||
const LOCAL_SIGNATURE = 0x04034b50;
|
||||
const LOCAL_FIXED_SIZE = 30;
|
||||
const ZIP64_SENTINEL = 0xffffffff;
|
||||
const FLAG_ENCRYPTED = 0x1;
|
||||
const FLAG_DATA_DESCRIPTOR = 0x8;
|
||||
@@ -441,7 +443,7 @@ export const localEntryData = (
|
||||
return err({ detail: "Zip64 entry sizes are not read" });
|
||||
const at = entry.localHeaderOffset;
|
||||
const limit = Math.min(entriesEnd, bytes.length);
|
||||
if (at + LOCAL_FIXED_SIZE > limit)
|
||||
if (at + ZIP_LOCAL_HEADER_BYTES > limit)
|
||||
return err({
|
||||
detail: `local header at byte ${String(at)} is out of range`,
|
||||
});
|
||||
@@ -450,7 +452,7 @@ export const localEntryData = (
|
||||
true,
|
||||
"zip",
|
||||
);
|
||||
if (reader.u32(at) !== LOCAL_SIGNATURE)
|
||||
if (reader.u32(at) !== ZIP_LOCAL_HEADER_SIGNATURE)
|
||||
return err({
|
||||
detail: `local header signature mismatch at byte ${String(at)}`,
|
||||
});
|
||||
@@ -474,7 +476,7 @@ export const localEntryData = (
|
||||
});
|
||||
}
|
||||
const nameLength = reader.u16(at + 26);
|
||||
const nameStart = at + LOCAL_FIXED_SIZE;
|
||||
const nameStart = at + ZIP_LOCAL_HEADER_BYTES;
|
||||
if (
|
||||
nameStart + nameLength > limit ||
|
||||
// apksig refuses a local name longer in bytes before decoding either.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BinaryReader } from "../binaryContainer.js";
|
||||
|
||||
export const ZIP_LOCAL_HEADER_BYTES = 30;
|
||||
const ZIP_LOCAL_HEADER_SIGNATURE = 0x04034b50;
|
||||
export const ZIP_LOCAL_HEADER_SIGNATURE = 0x04034b50;
|
||||
|
||||
/** Locate the data after the fixed header, file name and extra field. */
|
||||
export const zipLocalDataOffset = (
|
||||
|
||||
@@ -25,6 +25,8 @@ import { jsonObjectSchema } from "../../domain/jsonValue.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { nativeAotAdapter } from "./nativeaot/NativeAotAdapter.js";
|
||||
import { sha256Hex } from "../../kernel/sha256Hex.js";
|
||||
import { BinaryReader } from "../../domain/binaryContainer.js";
|
||||
import { ZIP_LOCAL_HEADER_SIGNATURE } from "../../domain/zip/zipLocalHeader.js";
|
||||
|
||||
const digest = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
/** Exact executable extension artifact committed before the session starts. */
|
||||
@@ -89,7 +91,11 @@ const readJar = (
|
||||
resources,
|
||||
signal,
|
||||
(bytes) => {
|
||||
if (bytes.length < 4 || bytes.readUInt32LE(0) !== 0x04034b50)
|
||||
if (
|
||||
bytes.length < 4 ||
|
||||
new BinaryReader(bytes, true, "jar").u32(0) !==
|
||||
ZIP_LOCAL_HEADER_SIGNATURE
|
||||
)
|
||||
throw new GhidraAdmissionError("not_jar", { path });
|
||||
return bytes;
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user