🛡️ 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.
JavaScript adversarial-aiclaude-codecursorelectron-securityllm-securitymcpmcp-serverobfuscationreverse-engineeringwebassembly
fix: reject negative zero in model header numbers
Codex4a639af55d14
diff --git a/README.md b/README.mdindex 95b0df6..bd15125 100644--- a/README.md+++ b/README.md@@ -307,7 +307,8 @@ subset is `BOOL`, `U8`, `I8`, `U16`, `I16`, `F16`, `BF16`, `U32`, `I32`, `F32`,`I64`, and `F64`. Other dtypes are reported as unsupported; this is not a claim thatthose models are invalid. Headers above 100 MB and integers beyond JavaScript'ssafe range are refused rather than silently rounded. Numeric tokens anywhere in-headers must use integer notation; fractional or exponent notation is unsupported,+headers must use nonnegative integer notation; negative tokens (including `-0`),+fractional notation, and exponent notation are unsupported,even if its mathematical value is integral. This lexical check prevents JSONparsing from silently rounding malformed dimensions/offsets into accepted values.Numbers inside string metadata remain unchanged.diff --git a/src/shields/formats/model.ts b/src/shields/formats/model.tsindex 4bb15e2..8d4d347 100644--- a/src/shields/formats/model.ts+++ b/src/shields/formats/model.ts@@ -58,9 +58,8 @@ 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) ||- BigInt(value) < BigInt(Number.MIN_SAFE_INTEGER)) {- fail("unsupported numeric token: require safe integer notation");+ if (!/^\d+$/.test(value) || BigInt(value) > BigInt(Number.MAX_SAFE_INTEGER)) {+ fail("unsupported numeric token: require nonnegative safe integer notation");}} else {const decoded = JSON.parse(value) as string;diff --git a/tests/safetensors-integrity.test.ts b/tests/safetensors-integrity.test.tsindex 1274889..24aef5f 100644--- a/tests/safetensors-integrity.test.ts+++ b/tests/safetensors-integrity.test.ts@@ -73,15 +73,15 @@ 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"])(+ it.each(["1.0000000000000001", "1.5", "1e0", "1e-999", "1e999", "9007199254740993", "-0"])("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/);expect(inspectModelBuffer(bytes).validModel).toBe(false);},);- it("also rejects fractional offset notation that rounds to an integer", () => {- const bytes = rawHeader('{"x":{"dtype":"F32","shape":[1],"data_offsets":[0,4.0000000000000001]}}', data.subarray(0, 4));+ it.each(["4.0000000000000001", "-0"])("rejects unsupported offset token %s", token => {+ const bytes = rawHeader(`{"x":{"dtype":"F32","shape":[1],"data_offsets":[${token === "-0" ? "-0,4" : `0,${token}`}]}}`, data.subarray(0, 4));expect(() => protectSafetensorsBuffer(bytes)).toThrow(/unsupported numeric token/);});it("explicitly reports unsupported dtypes rather than rewriting them", () => {