Skip to content

armgit / bla

Public Imported from GitHub
0

🛡️ BLA (Blind LLM Agents) — Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, and WebAssembly against AI reverse-engineering agents like REA. Poison -> Exhaust -> Hallucinate.

fix: bound model numeric tokens before BigInt conversion

Codex91b3953287b0
diff --git a/src/shields/formats/model.ts b/src/shields/formats/model.ts
index 8d4d347..c77c025 100644
--- a/src/shields/formats/model.ts
+++ b/src/shields/formats/model.ts
@@ -58,7 +58,7 @@ export function validateSafetensorsBuffer(bytes: Buffer): {
// JSON.parse rounds before Number.isSafeInteger can inspect the value.
// The supported header subset requires integer lexical tokens, not
// fractions/exponents even when they would round to an integer.
- if (!/^\d+$/.test(value) || BigInt(value) > BigInt(Number.MAX_SAFE_INTEGER)) {
+ if (value.length > 16 || !/^\d+$/.test(value) || BigInt(value) > BigInt(Number.MAX_SAFE_INTEGER)) {
fail("unsupported numeric token: require nonnegative safe integer notation");
}
} else {
diff --git a/tests/safetensors-integrity.test.ts b/tests/safetensors-integrity.test.ts
index 24aef5f..316da6c 100644
--- a/tests/safetensors-integrity.test.ts
+++ b/tests/safetensors-integrity.test.ts
@@ -73,7 +73,7 @@ describe("Safetensors format and tensor preservation (not inference)", () => {
expect(inspectModelBuffer(bytes).validModel).toBe(false);
expect(bytes).toEqual(snapshot);
});
- it.each(["1.0000000000000001", "1.5", "1e0", "1e-999", "1e999", "9007199254740993", "-0"])(
+ it.each(["1.0000000000000001", "1.5", "1e0", "1e-999", "1e999", "9007199254740993", "-0", "9".repeat(128)])(
"rejects unsupported numeric token %s before rounded values can be accepted", token => {
const bytes = rawHeader(`{"x":{"dtype":"F32","shape":[${token}],"data_offsets":[0,4]}}`, data.subarray(0, 4));
expect(() => protectSafetensorsBuffer(bytes)).toThrow(/unsupported numeric token/);
@@ -108,7 +108,13 @@ describe("Safetensors malformed input no-write admission", () => {
{ inputPath: input }, { inputPath: input, inPlace: true },
{ inputPath: input, outputPath: input }, { inputPath: input, outputPath: output },
{ inputPath: input, outputPath: join(dir, "new", "out.safetensors") },
- ]) expect(() => protectTarget(options)).toThrow(InvalidSafetensorsError);
+ ]) {
+ if (options.outputPath === input && !options.inPlace) {
+ expect(() => protectTarget(options)).toThrow(/Output refers to the input file/);
+ } else {
+ expect(() => protectTarget(options)).toThrow(InvalidSafetensorsError);
+ }
+ }
expect(readFileSync(input)).toEqual(bad);
expect(readFileSync(output)).toEqual(original);
expect(existsSync(join(dir, "new"))).toBe(false);