@poe-platform/safe-bash 0.1.80 → 0.1.82

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.
@@ -4653,6 +4653,23 @@ function streamCommands() {
4653
4653
 
4654
4654
  // packages/safe-bash/src/commands/text.ts
4655
4655
  init_platform();
4656
+
4657
+ // packages/safe-bash/src/commands/sort-admission.ts
4658
+ init_platform();
4659
+ var SortRecordBudget = class {
4660
+ #records = 0;
4661
+ #bytes = 0;
4662
+ admit(byteLength2) {
4663
+ const bytes2 = byteLength2 + 1;
4664
+ if (this.#records >= 1e5 || bytes2 > bufferLimit - this.#bytes) {
4665
+ throw new FsError("EFBIG", { message: "sort buffer limit exceeded" });
4666
+ }
4667
+ this.#records++;
4668
+ this.#bytes += bytes2;
4669
+ }
4670
+ };
4671
+
4672
+ // packages/safe-bash/src/commands/text.ts
4656
4673
  var SortWork = class {
4657
4674
  constructor(signal) {
4658
4675
  this.signal = signal;
@@ -4921,20 +4938,25 @@ async function emitRecords(context, records, destination) {
4921
4938
  await context.fs.writeFile(pathOf(context, destination), concatenate(chunks, size), { signal: context.signal });
4922
4939
  }
4923
4940
  }
4924
- async function collectSortRecords(source, delimiter, accept) {
4941
+ async function collectSortRecords(source, delimiter, budget, signal, accept) {
4925
4942
  let pending = [];
4926
4943
  let size = 0;
4927
4944
  for await (const chunk of source) {
4928
4945
  let start = 0;
4929
4946
  for (let offset = 0; offset < chunk.length; offset++) {
4930
4947
  if (chunk[offset] !== delimiter) continue;
4931
- const part = chunk.subarray(start, offset);
4932
- size += part.length;
4948
+ size += offset - start;
4933
4949
  if (size > bufferLimit) throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
4950
+ signal.throwIfAborted();
4951
+ budget.admit(size);
4952
+ const part = chunk.subarray(start, offset);
4953
+ let record4;
4934
4954
  if (pending.length) {
4935
4955
  pending.push(part);
4936
- accept(concatenate(pending, size));
4937
- } else accept(new Uint8Array(part));
4956
+ record4 = concatenate(pending, size);
4957
+ } else record4 = new Uint8Array(part);
4958
+ const accepted = accept(record4);
4959
+ if ((accepted instanceof Promise ? await accepted : accepted) === false) return false;
4938
4960
  pending = [];
4939
4961
  size = 0;
4940
4962
  start = offset + 1;
@@ -4945,7 +4967,12 @@ async function collectSortRecords(source, delimiter, accept) {
4945
4967
  if (size > bufferLimit) throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
4946
4968
  }
4947
4969
  }
4948
- if (size) accept(concatenate(pending, size));
4970
+ if (size) {
4971
+ signal.throwIfAborted();
4972
+ budget.admit(size);
4973
+ return await accept(concatenate(pending, size)) !== false;
4974
+ }
4975
+ return true;
4949
4976
  }
4950
4977
  function textCommands() {
4951
4978
  return [
@@ -5037,30 +5064,26 @@ function textCommands() {
5037
5064
  return result || (simple || parsed.flags.has("s") || parsed.flags.has("u") ? 0 : await compareSortBytes(left, right, work) * direction);
5038
5065
  };
5039
5066
  const records = [];
5040
- let size = 0;
5067
+ const recordBudget = new SortRecordBudget();
5041
5068
  const exitCode = 0;
5042
5069
  const delimiter = parsed.flags.has("z") ? 0 : 10;
5043
5070
  for (const name2 of parsed.operands.length ? parsed.operands : ["-"]) {
5044
5071
  try {
5045
- if (!parsed.flags.has("c")) {
5046
- await collectSortRecords(input(context, name2), delimiter, (bytes2) => {
5047
- context.signal.throwIfAborted();
5048
- size += bytes2.length + 1;
5049
- if (size > bufferLimit) throw new FsError("EFBIG", { message: "sort buffer limit exceeded" });
5050
- records.push(bytes2);
5051
- });
5052
- continue;
5053
- }
5054
- for await (const line of lines(input(context, name2), delimiter)) {
5072
+ const complete2 = await collectSortRecords(input(context, name2), delimiter, recordBudget, context.signal, (bytes2) => {
5055
5073
  context.signal.throwIfAborted();
5056
- size += line.bytes.length + 1;
5057
- if (size > bufferLimit) throw new FsError("EFBIG", { message: "sort buffer limit exceeded" });
5058
- if (parsed.flags.has("c") && records.length && (await compare(records.at(-1), line.bytes) > 0 || parsed.flags.has("u") && await keyCompare(records.at(-1), line.bytes) === 0)) {
5059
- await diagnostic(context, new Error(`disorder at record ${records.length + 1}`));
5060
- return { exitCode: 1 };
5074
+ if (!parsed.flags.has("c")) {
5075
+ records.push(bytes2);
5076
+ return;
5061
5077
  }
5062
- records.push(line.bytes);
5063
- }
5078
+ return (async () => {
5079
+ if (records.length && (await compare(records.at(-1), bytes2) > 0 || parsed.flags.has("u") && await keyCompare(records.at(-1), bytes2) === 0)) {
5080
+ await diagnostic(context, new Error(`disorder at record ${records.length + 1}`));
5081
+ return false;
5082
+ }
5083
+ records.push(bytes2);
5084
+ })();
5085
+ });
5086
+ if (!complete2) return { exitCode: 1 };
5064
5087
  } catch (error) {
5065
5088
  await diagnostic(context, error);
5066
5089
  return { exitCode: 2 };
@@ -16368,19 +16391,31 @@ function createFetchTransport(options3 = {}) {
16368
16391
 
16369
16392
  // packages/safe-bash/src/commands/network/authorizer.ts
16370
16393
  init_platform();
16394
+ function privateIPv4(first, second) {
16395
+ return first === 10 || first === 127 || first === 0 || first === 169 && second === 254 || first === 192 && second === 168 || first === 172 && second >= 16 && second <= 31;
16396
+ }
16371
16397
  function privateHostname(input3) {
16372
16398
  const hostname = input3.toLowerCase().replace(/\.$/u, "").replace(/^\[|\]$/gu, "");
16373
16399
  if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "::1") return true;
16374
16400
  if (hostname.includes(":")) {
16375
- const first2 = hostname.split(":", 1)[0] ?? "";
16376
- return first2.startsWith("fc") || first2.startsWith("fd") || ["fe8", "fe9", "fea", "feb"].some((prefix2) => first2.startsWith(prefix2));
16401
+ const [prefix2, suffix2] = hostname.split("::");
16402
+ const leading = prefix2 ? prefix2.split(":") : [];
16403
+ const trailing = suffix2 ? suffix2.split(":") : [];
16404
+ const hextets = new Array(8).fill(0);
16405
+ for (let index = 0; index < leading.length; index++) hextets[index] = Number.parseInt(leading[index], 16);
16406
+ for (let index = 0; index < trailing.length; index++) hextets[8 - trailing.length + index] = Number.parseInt(trailing[index], 16);
16407
+ if (hextets.every((value2) => value2 === 0)) return true;
16408
+ if (hextets.slice(0, 5).every((value2) => value2 === 0) && hextets[5] === 65535) {
16409
+ return privateIPv4(hextets[6] >>> 8, hextets[6] & 255);
16410
+ }
16411
+ return (hextets[0] & 65024) === 64512 || (hextets[0] & 65472) === 65152;
16377
16412
  }
16378
16413
  const parts = hostname.split(".");
16379
16414
  if (parts.length !== 4 || parts.some((part) => !part || Array.from(part).some((character) => character < "0" || character > "9"))) return false;
16380
16415
  const octets = parts.map(Number);
16381
16416
  if (octets.some((value2) => value2 < 0 || value2 > 255)) return false;
16382
16417
  const [first, second] = octets;
16383
- return first === 10 || first === 127 || first === 0 || first === 169 && second === 254 || first === 192 && second === 168 || first === 172 && second >= 16 && second <= 31;
16418
+ return privateIPv4(first, second);
16384
16419
  }
16385
16420
  function createOriginAuthorizer(allowlist = "*", options3 = {}) {
16386
16421
  const origins = /* @__PURE__ */ new Set();