@bman654/clodex 2.8.4 → 2.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -382,7 +382,7 @@ import { join } from "path";
382
382
  // package.json
383
383
  var package_default = {
384
384
  name: "@bman654/clodex",
385
- version: "2.8.4",
385
+ version: "2.8.5",
386
386
  publishConfig: {
387
387
  access: "public"
388
388
  },
@@ -3820,7 +3820,7 @@ function applyClodexPatches(source, config) {
3820
3820
  const bound = braceScanFailed ? 0 : closingBrace - at - (match.length - 1);
3821
3821
  const missingLiteral = requiredBodyLiterals.find((literal) => !body.includes(literal));
3822
3822
  const scrubbedSeen = scrubbedEnvNames.filter((name) => body.includes(name));
3823
- const why = missingLiteral !== void 0 ? "body does not contain " + missingLiteral : scrubbedSeen.length < MIN_SCRUBBED_ENV_NAMES ? "body scrubs only " + scrubbedSeen.length + " of the " + scrubbedEnvNames.length + " known child-env names (expected at least " + MIN_SCRUBBED_ENV_NAMES + ")" : /\bfunction\s*[\w$]*\(/.test(body) ? "body declares a nested function" : braceScanFailed ? "the brace walk never reached the function's closing brace" : bound !== 0 ? "match ends " + bound + " characters from the function it started in" : void 0;
3823
+ const why = missingLiteral !== void 0 ? "body does not contain " + missingLiteral : scrubbedSeen.length < MIN_SCRUBBED_ENV_NAMES ? "body spells only " + scrubbedSeen.length + " of the " + scrubbedEnvNames.length + " known child-env names (expected at least " + MIN_SCRUBBED_ENV_NAMES + ")" : /\bfunction\s*[\w$]*\(/.test(body) ? "body declares a nested function" : braceScanFailed ? "the brace walk never reached the function's closing brace" : bound !== 0 ? "match ends " + Math.abs(bound) + " characters " + (bound > 0 ? "before" : "after") + " the end of the function it started in" : void 0;
3824
3824
  if (why !== void 0) {
3825
3825
  log12("FAIL", patchName, "target validation failed: " + why);
3826
3826
  fail("clodex patch: child network environment target validation failed: " + why);
@@ -7066,7 +7066,7 @@ function resignMachOBinary(path) {
7066
7066
  }
7067
7067
 
7068
7068
  // src/bun-compiled-pointer.ts
7069
- import { closeSync as closeSync3, openSync as openSync3, readSync as readSync2, writeSync as writeSync3 } from "fs";
7069
+ import { closeSync as closeSync3, fstatSync, openSync as openSync3, readSync as readSync2, writeSync as writeSync3 } from "fs";
7070
7070
  var TWEAKCC_SCAN_STRIDE = 16384n;
7071
7071
  var SCAN_CHUNK = 1 << 20;
7072
7072
  var ELF_MAGIC = 1179403647;
@@ -7098,6 +7098,9 @@ function readElfLayout(fd) {
7098
7098
  const shstrndx = ident.readUInt16LE(62);
7099
7099
  if (shnum === 0 || phnum === 65535) return null;
7100
7100
  if (shstrndx >= shnum || shentsize < 64 || phentsize < 56) return null;
7101
+ const fileSize = fstatSync(fd).size;
7102
+ const fits = (offset, length) => Number.isSafeInteger(offset) && offset >= 0 && length >= 0 && offset + length <= fileSize;
7103
+ if (!fits(Number(shoff), shnum * shentsize)) return null;
7101
7104
  const shTable = readAt2(fd, shnum * shentsize, Number(shoff));
7102
7105
  if (shTable.length !== shnum * shentsize) return null;
7103
7106
  const raw = [];
@@ -7111,6 +7114,7 @@ function readElfLayout(fd) {
7111
7114
  });
7112
7115
  }
7113
7116
  const strtab = raw[shstrndx];
7117
+ if (!fits(Number(strtab.offset), Number(strtab.size))) return null;
7114
7118
  const names = readAt2(fd, Number(strtab.size), Number(strtab.offset));
7115
7119
  const sections = raw.map((section) => {
7116
7120
  const start = section.nameOffset;
@@ -7123,6 +7127,7 @@ function readElfLayout(fd) {
7123
7127
  size: section.size
7124
7128
  };
7125
7129
  });
7130
+ if (!fits(Number(phoff), phnum * phentsize)) return null;
7126
7131
  const phTable = readAt2(fd, phnum * phentsize, Number(phoff));
7127
7132
  if (phTable.length !== phnum * phentsize) return null;
7128
7133
  const segments = [];
@@ -7192,7 +7197,6 @@ function shimBunCompiledPointer(path) {
7192
7197
  if (!segment) return null;
7193
7198
  const needle = Buffer.alloc(8);
7194
7199
  needle.writeBigUInt64LE(bun.addr);
7195
- if (tweakccWouldFind(fd, segment, needle) !== null) return null;
7196
7200
  const segmentStart = Number(segment.offset);
7197
7201
  const segmentEnd = Number(segment.offset + segment.filesz);
7198
7202
  const bunStart = Number(bun.offset);
@@ -7205,6 +7209,15 @@ function shimBunCompiledPointer(path) {
7205
7209
  }
7206
7210
  const pointerOffset = candidates[0];
7207
7211
  const pointerVaddr = segment.vaddr + BigInt(pointerOffset) - segment.offset;
7212
+ const wouldFind = tweakccWouldFind(fd, segment, needle);
7213
+ if (wouldFind !== null) {
7214
+ if (wouldFind !== pointerVaddr) {
7215
+ throw new Error(
7216
+ `tweakcc's ELF repack would rewrite 0x${wouldFind.toString(16)}, which is not Bun's blob pointer at 0x${pointerVaddr.toString(16)}. Refusing to repack a binary whose Bun global would be left stale.`
7217
+ );
7218
+ }
7219
+ return null;
7220
+ }
7208
7221
  const first = alignUp(segment.vaddr, TWEAKCC_SCAN_STRIDE);
7209
7222
  const last = segment.vaddr + segment.filesz - 8n;
7210
7223
  let standInVaddr = null;
@@ -7241,7 +7254,11 @@ function restoreBunCompiledPointer(path, shim) {
7241
7254
  "the repack left Bun's blob pointer outside the loaded image, or in more than one segment of it"
7242
7255
  );
7243
7256
  }
7244
- const written = readAt2(fd, 8, standInOffset).readBigUInt64LE(0);
7257
+ const standIn = readAt2(fd, 8, standInOffset);
7258
+ if (standIn.length !== 8) {
7259
+ throw new Error("the repacked binary ends before the stand-in for Bun's blob pointer");
7260
+ }
7261
+ const written = standIn.readBigUInt64LE(0);
7245
7262
  if (written === shim.bunVaddr) {
7246
7263
  throw new Error("the repack did not rewrite Bun's blob pointer \u2014 the stand-in was not used");
7247
7264
  }
@@ -13516,7 +13533,7 @@ import { randomUUID as randomUUID4 } from "crypto";
13516
13533
  import {
13517
13534
  closeSync as closeSync7,
13518
13535
  existsSync as existsSync6,
13519
- fstatSync,
13536
+ fstatSync as fstatSync2,
13520
13537
  fsyncSync as fsyncSync2,
13521
13538
  lstatSync,
13522
13539
  mkdirSync as mkdirSync6,
@@ -13613,7 +13630,7 @@ function readJournalUnlocked(path) {
13613
13630
  throw new Error("Credential cleanup journal must be a regular file.");
13614
13631
  }
13615
13632
  fd = openSync7(path, "r");
13616
- const opened = fstatSync(fd);
13633
+ const opened = fstatSync2(fd);
13617
13634
  if (before.dev !== opened.dev || before.ino !== opened.ino) {
13618
13635
  throw new Error("Credential cleanup journal changed while opening.");
13619
13636
  }