owenloop 0.5.0 → 0.5.1

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.
Files changed (211) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +137 -35
  3. package/bin/owenloop.mjs +49 -1
  4. package/dist/packages/work/src/agent/brief.d.ts +8 -4
  5. package/dist/packages/work/src/agent/brief.js +7 -3
  6. package/dist/packages/work/src/agent/loop.d.ts +13 -7
  7. package/dist/packages/work/src/agent/loop.js +136 -9
  8. package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
  9. package/dist/packages/work/src/agent/model-policy.js +138 -0
  10. package/dist/packages/work/src/bundle/cache.d.ts +7 -5
  11. package/dist/packages/work/src/bundle/cache.js +20 -6
  12. package/dist/packages/work/src/bundle/fetch.d.ts +7 -5
  13. package/dist/packages/work/src/bundle/fetch.js +27 -7
  14. package/dist/packages/work/src/bundle/types.d.ts +8 -4
  15. package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
  16. package/dist/packages/work/src/consumed-verifier.js +205 -0
  17. package/dist/packages/work/src/exec/instructions.d.ts +99 -0
  18. package/dist/packages/work/src/exec/instructions.js +323 -0
  19. package/dist/packages/work/src/exec/loop.d.ts +12 -1
  20. package/dist/packages/work/src/exec/loop.js +137 -20
  21. package/dist/packages/work/src/exec/payload.d.ts +29 -0
  22. package/dist/packages/work/src/exec/payload.js +54 -0
  23. package/dist/packages/work/src/exec/receipt.d.ts +9 -6
  24. package/dist/packages/work/src/exec/receipt.js +12 -1
  25. package/dist/packages/work/src/exec/runner.d.ts +7 -1
  26. package/dist/packages/work/src/exec/runner.js +74 -3
  27. package/dist/packages/work/src/harness/child-env.js +7 -0
  28. package/dist/packages/work/src/harness/claude.d.ts +20 -8
  29. package/dist/packages/work/src/harness/claude.js +260 -58
  30. package/dist/packages/work/src/harness/codex.d.ts +5 -4
  31. package/dist/packages/work/src/harness/codex.js +169 -41
  32. package/dist/packages/work/src/harness/contract.d.ts +36 -11
  33. package/dist/packages/work/src/harness/fake.js +1 -0
  34. package/dist/packages/work/src/harness/jsonrpc-stdio.js +7 -0
  35. package/dist/packages/work/src/harness/permissions.d.ts +16 -3
  36. package/dist/packages/work/src/harness/permissions.js +102 -13
  37. package/dist/packages/work/src/harness/session-store.d.ts +27 -9
  38. package/dist/packages/work/src/harness/session-store.js +271 -67
  39. package/dist/packages/work/src/hold/mcp.d.ts +25 -5
  40. package/dist/packages/work/src/hold/mcp.js +126 -11
  41. package/dist/packages/work/src/hub/client.d.ts +2 -1
  42. package/dist/packages/work/src/hub/client.js +14 -1
  43. package/dist/packages/work/src/hub/types.d.ts +69 -33
  44. package/dist/packages/work/src/hub/types.js +8 -10
  45. package/dist/packages/work/src/mcp/server.js +1 -1
  46. package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
  47. package/dist/packages/work/src/owenloop-bin.js +18 -0
  48. package/dist/packages/work/src/roles/agent-run.d.ts +12 -6
  49. package/dist/packages/work/src/roles/agent-run.js +116 -34
  50. package/dist/packages/work/src/roles/exec.d.ts +8 -0
  51. package/dist/packages/work/src/roles/exec.js +27 -2
  52. package/dist/packages/work/src/roles/hold.d.ts +4 -0
  53. package/dist/packages/work/src/roles/hold.js +44 -5
  54. package/dist/packages/work/src/roles/lint.d.ts +3 -4
  55. package/dist/packages/work/src/roles/lint.js +41 -7
  56. package/dist/packages/work/src/roles/settings.js +5 -0
  57. package/dist/packages/work/src/roles/shift.d.ts +1 -0
  58. package/dist/packages/work/src/roles/shift.js +23 -1
  59. package/dist/packages/work/src/settings/settings.d.ts +17 -1
  60. package/dist/packages/work/src/settings/settings.js +39 -0
  61. package/dist/packages/work/src/shift/loop.d.ts +14 -3
  62. package/dist/packages/work/src/shift/loop.js +447 -164
  63. package/dist/packages/work/src/shift/protocol.d.ts +4 -0
  64. package/dist/packages/work/src/shift/runtime.d.ts +2 -0
  65. package/dist/packages/work/src/shift/runtime.js +66 -3
  66. package/dist/packages/work/src/shift/spawn.d.ts +41 -18
  67. package/dist/packages/work/src/shift/spawn.js +89 -31
  68. package/dist/packages/work/src/shift/state.d.ts +53 -51
  69. package/dist/packages/work/src/shift/state.js +325 -102
  70. package/dist/packages/work/src/submit-proof.d.ts +36 -0
  71. package/dist/packages/work/src/submit-proof.js +93 -0
  72. package/dist/src/add.d.ts +64 -259
  73. package/dist/src/add.js +81 -615
  74. package/dist/src/archive.d.ts +97 -0
  75. package/dist/src/archive.js +591 -0
  76. package/dist/src/bundle/index.d.ts +64 -0
  77. package/dist/src/bundle/index.js +508 -0
  78. package/dist/src/bundle/manifest.d.ts +50 -0
  79. package/dist/src/bundle/manifest.js +435 -0
  80. package/dist/src/bundle/runtime.d.ts +26 -0
  81. package/dist/src/bundle/runtime.js +64 -0
  82. package/dist/src/bundle/tar.d.ts +62 -0
  83. package/dist/src/bundle/tar.js +238 -0
  84. package/dist/src/bundle/types.d.ts +105 -0
  85. package/dist/src/bundle/types.js +21 -0
  86. package/dist/src/cli.d.ts +90 -20
  87. package/dist/src/cli.js +2407 -365
  88. package/dist/src/credentials.d.ts +4 -3
  89. package/dist/src/credentials.js +21 -19
  90. package/dist/src/crypto/allowed-signers.d.ts +68 -0
  91. package/dist/src/crypto/allowed-signers.js +307 -0
  92. package/dist/src/crypto/canonical.d.ts +8 -0
  93. package/dist/src/crypto/canonical.js +92 -0
  94. package/dist/src/crypto/chain.d.ts +65 -0
  95. package/dist/src/crypto/chain.js +377 -0
  96. package/dist/src/crypto/dsse.d.ts +209 -0
  97. package/dist/src/crypto/dsse.js +282 -0
  98. package/dist/src/crypto/enrollment.d.ts +78 -0
  99. package/dist/src/crypto/enrollment.js +186 -0
  100. package/dist/src/crypto/index.d.ts +48 -0
  101. package/dist/src/crypto/index.js +44 -0
  102. package/dist/src/crypto/keys.d.ts +258 -0
  103. package/dist/src/crypto/keys.js +908 -0
  104. package/dist/src/crypto/org-root.d.ts +33 -0
  105. package/dist/src/crypto/org-root.js +78 -0
  106. package/dist/src/crypto/origin-rules.d.ts +56 -0
  107. package/dist/src/crypto/origin-rules.js +143 -0
  108. package/dist/src/crypto/policy-floor.d.ts +98 -0
  109. package/dist/src/crypto/policy-floor.js +353 -0
  110. package/dist/src/crypto/records.d.ts +316 -0
  111. package/dist/src/crypto/records.js +157 -0
  112. package/dist/src/crypto/scope.d.ts +49 -0
  113. package/dist/src/crypto/scope.js +83 -0
  114. package/dist/src/crypto/ssh.d.ts +171 -0
  115. package/dist/src/crypto/ssh.js +396 -0
  116. package/dist/src/crypto/submission.d.ts +33 -0
  117. package/dist/src/crypto/submission.js +47 -0
  118. package/dist/src/crypto/trust-roots.d.ts +29 -0
  119. package/dist/src/crypto/trust-roots.js +39 -0
  120. package/dist/src/crypto/verify-consumed.d.ts +67 -0
  121. package/dist/src/crypto/verify-consumed.js +259 -0
  122. package/dist/src/crypto/verify-origin.d.ts +50 -0
  123. package/dist/src/crypto/verify-origin.js +151 -0
  124. package/dist/src/crypto/verify-publication.d.ts +60 -0
  125. package/dist/src/crypto/verify-publication.js +150 -0
  126. package/dist/src/defs.d.ts +24 -1
  127. package/dist/src/defs.js +145 -25
  128. package/dist/src/engine.d.ts +99 -3
  129. package/dist/src/engine.js +238 -34
  130. package/dist/src/factory.d.ts +16 -0
  131. package/dist/src/factory.js +16 -4
  132. package/dist/src/global-config.d.ts +59 -0
  133. package/dist/src/global-config.js +84 -0
  134. package/dist/src/hub.d.ts +75 -21
  135. package/dist/src/hub.js +123 -40
  136. package/dist/src/index.d.ts +17 -2
  137. package/dist/src/index.js +20 -2
  138. package/dist/src/install.d.ts +538 -0
  139. package/dist/src/install.js +1981 -0
  140. package/dist/src/lock.d.ts +15 -57
  141. package/dist/src/lock.js +251 -143
  142. package/dist/src/mcp/serve.d.ts +46 -22
  143. package/dist/src/mcp/serve.js +167 -44
  144. package/dist/src/mcp/server.js +12 -1
  145. package/dist/src/model.d.ts +15 -0
  146. package/dist/src/model.js +111 -1
  147. package/dist/src/order-resolver.d.ts +184 -0
  148. package/dist/src/order-resolver.js +252 -0
  149. package/dist/src/package-version.d.ts +10 -0
  150. package/dist/src/package-version.js +42 -0
  151. package/dist/src/paths.d.ts +14 -1
  152. package/dist/src/paths.js +18 -0
  153. package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
  154. package/dist/src/schemas/index.d.ts +1416 -0
  155. package/dist/src/schemas/index.js +31 -0
  156. package/dist/src/schemas/order.v1.schema.json +106 -0
  157. package/dist/src/schemas/origin.v1.schema.json +68 -0
  158. package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
  159. package/dist/src/schemas/publication.v1.schema.json +31 -0
  160. package/dist/src/schemas/revocation.v1.schema.json +39 -0
  161. package/dist/src/schemas/submission.v1.schema.json +61 -0
  162. package/dist/src/store/def-source.d.ts +52 -0
  163. package/dist/src/store/def-source.js +335 -0
  164. package/dist/src/store/index-file.d.ts +69 -0
  165. package/dist/src/store/index-file.js +151 -0
  166. package/dist/src/store/index.d.ts +27 -0
  167. package/dist/src/store/index.js +22 -0
  168. package/dist/src/store/ingestor.d.ts +43 -0
  169. package/dist/src/store/ingestor.js +211 -0
  170. package/dist/src/store/install.d.ts +228 -0
  171. package/dist/src/store/install.js +555 -0
  172. package/dist/src/store/instruction-source.d.ts +49 -0
  173. package/dist/src/store/instruction-source.js +298 -0
  174. package/dist/src/store/origin-evidence.d.ts +21 -0
  175. package/dist/src/store/origin-evidence.js +66 -0
  176. package/dist/src/store/pre-commit-verifier.d.ts +68 -0
  177. package/dist/src/store/pre-commit-verifier.js +418 -0
  178. package/dist/src/store/resolve.d.ts +138 -0
  179. package/dist/src/store/resolve.js +363 -0
  180. package/dist/src/store/types.d.ts +288 -0
  181. package/dist/src/store/types.js +356 -0
  182. package/dist/src/types.d.ts +45 -11
  183. package/dist/src/untar.d.ts +8 -23
  184. package/dist/src/untar.js +10 -136
  185. package/docs/agent-runner.md +86 -0
  186. package/docs/authoring.md +57 -6
  187. package/docs/bundles.md +250 -0
  188. package/docs/cli.md +1171 -97
  189. package/docs/crypto.md +816 -0
  190. package/docs/design.md +342 -20
  191. package/docs/embedding.md +132 -25
  192. package/docs/wire-contracts.md +380 -0
  193. package/package.json +6 -1
  194. package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
  195. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
  196. package/plugins/claude-code/plugin/.mcp.json +14 -0
  197. package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
  198. package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
  199. package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
  200. package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
  201. package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
  202. package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
  203. package/plugins/codex/.agents/plugins/marketplace.json +21 -0
  204. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
  205. package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
  206. package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
  207. package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
  208. package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
  209. package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
  210. package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
  211. package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Shared archive safety primitives: the ONE archive/path security policy used
3
+ * by `add` (GitHub tarball installs, via `src/untar.ts`), the `.wnlp` bundle
4
+ * reader/writer (`src/bundle/`), and the CLI glue around them.
5
+ *
6
+ * Two reading policies share one parser:
7
+ *
8
+ * - `compatible` — the historical `extractTarGz` behavior for GitHub
9
+ * tarballs: regular files are returned, directory and pax-global metadata is
10
+ * ignored after validation, and unsupported content entries are skipped.
11
+ * - `strict` — the `.wnlp` bundle policy: only canonical regular-file entries
12
+ * and their deterministic POSIX PAX path headers are accepted. Unsafe types,
13
+ * malformed headers, duplicate paths, non-canonical order, and trailing
14
+ * bytes are rejected with stable named codes.
15
+ *
16
+ * Resource bounds are checked before the parser copies entry data. Compressed
17
+ * input is bounded before inflation; gzip inflation is capped by zlib; every
18
+ * tar header counts toward the entry bound; and regular-file sizes and paths
19
+ * are checked before a returned entry is allocated.
20
+ */
21
+ /**
22
+ * Resource bounds enforced while reading an archive. Defaults are sized for
23
+ * GitHub codeload output and are deliberately generous; tests inject tiny
24
+ * values to exercise the limits without building giant fixtures.
25
+ */
26
+ export interface TarLimits {
27
+ maxCompressedBytes: number;
28
+ maxExpandedBytes: number;
29
+ /** Counts every non-terminator tar header, including PAX headers. */
30
+ maxFileCount: number;
31
+ maxFileBytes: number;
32
+ maxPathLength: number;
33
+ }
34
+ export declare const DEFAULT_TAR_LIMITS: TarLimits;
35
+ /** Max length for an in-archive relative path we are willing to join and write. */
36
+ export declare const MAX_ARCHIVE_PATH_LENGTH = 1024;
37
+ /**
38
+ * Returns `undefined` if `relPath` is safe to `join()` under a destination
39
+ * directory, else a human-readable reason it must be rejected. This is
40
+ * reject-don't-normalize: an unnormalized archive name is refused outright,
41
+ * never canonicalized into a safe-looking path.
42
+ */
43
+ export declare function archivePathViolation(relPath: string): string | undefined;
44
+ /**
45
+ * The canonical `.wnlp` path policy. GitHub archive compatibility deliberately
46
+ * keeps using {@link archivePathViolation}; bundle paths add the portable rule
47
+ * that `/` is the only separator, so a backslash is rejected rather than being
48
+ * interpreted differently by POSIX and Windows filesystems.
49
+ */
50
+ export declare function canonicalBundlePathViolation(relPath: string): string | undefined;
51
+ /** Return the prior regular-file path that would have to be a directory for `path`. */
52
+ export declare function canonicalBundleFilePrefix(path: string, priorFilePaths: ReadonlySet<string>): string | undefined;
53
+ /**
54
+ * Bounded gzip inflation. The compressed-size check happens before zlib sees
55
+ * the input, and `maxOutputLength` caps expansion itself.
56
+ */
57
+ export declare function inflateArchive(bytes: Uint8Array, limits: TarLimits): Buffer;
58
+ /** Stable violation codes for strict archive parsing (`.wnlp` reading). */
59
+ export type ArchiveViolationCode = 'ARCHIVE_TOO_MANY_ENTRIES' | 'ARCHIVE_ENTRY_TOO_LARGE' | 'ARCHIVE_PATH_TOO_LONG' | 'ARCHIVE_PATH_VIOLATION' | 'ARCHIVE_DUPLICATE_PATH' | 'ARCHIVE_PATH_PREFIX_COLLISION' | 'ARCHIVE_TRUNCATED' | 'ARCHIVE_BAD_CHECKSUM' | 'ARCHIVE_BAD_OCTAL' | 'ARCHIVE_BAD_PAX' | 'ARCHIVE_DANGLING_PAX' | 'ARCHIVE_TRAILING_BYTES' | 'UNSUPPORTED_ENTRY_TYPE' | 'NON_CANONICAL_HEADER';
60
+ /** A strict-policy archive violation with machine-readable detail. */
61
+ export declare class ArchiveViolation extends Error {
62
+ readonly code: ArchiveViolationCode;
63
+ readonly entryPath?: string;
64
+ readonly typeflag?: string;
65
+ constructor(code: ArchiveViolationCode, message: string, detail?: {
66
+ entryPath?: string;
67
+ typeflag?: string;
68
+ });
69
+ }
70
+ /**
71
+ * The deterministic USTAR name placeholder paired with a canonical PAX path.
72
+ * The writer uses the first 100 UTF-8 bytes when that slice ends on a
73
+ * character boundary; otherwise it uses the fixed ASCII `PaxData` marker.
74
+ */
75
+ export declare function canonicalPaxNamePlaceholder(path: string): string;
76
+ /** One parsed regular-file entry (the only entry kind returned to callers). */
77
+ export interface TarEntry {
78
+ path: string;
79
+ size: number;
80
+ mode: number;
81
+ uid: number;
82
+ gid: number;
83
+ uname: string;
84
+ gname: string;
85
+ mtime: number;
86
+ typeflag: '0';
87
+ hadPaxPath: boolean;
88
+ data: Uint8Array;
89
+ }
90
+ export interface ParseTarOptions {
91
+ policy: 'compatible' | 'strict';
92
+ }
93
+ /**
94
+ * Parse an UNCOMPRESSED tar stream. Compatible mode retains the historical
95
+ * extractor contract; strict mode accepts only canonical package archives.
96
+ */
97
+ export declare function parseTar(tar: Uint8Array, limits: TarLimits, opts: ParseTarOptions): TarEntry[];
@@ -0,0 +1,591 @@
1
+ /**
2
+ * Shared archive safety primitives: the ONE archive/path security policy used
3
+ * by `add` (GitHub tarball installs, via `src/untar.ts`), the `.wnlp` bundle
4
+ * reader/writer (`src/bundle/`), and the CLI glue around them.
5
+ *
6
+ * Two reading policies share one parser:
7
+ *
8
+ * - `compatible` — the historical `extractTarGz` behavior for GitHub
9
+ * tarballs: regular files are returned, directory and pax-global metadata is
10
+ * ignored after validation, and unsupported content entries are skipped.
11
+ * - `strict` — the `.wnlp` bundle policy: only canonical regular-file entries
12
+ * and their deterministic POSIX PAX path headers are accepted. Unsafe types,
13
+ * malformed headers, duplicate paths, non-canonical order, and trailing
14
+ * bytes are rejected with stable named codes.
15
+ *
16
+ * Resource bounds are checked before the parser copies entry data. Compressed
17
+ * input is bounded before inflation; gzip inflation is capped by zlib; every
18
+ * tar header counts toward the entry bound; and regular-file sizes and paths
19
+ * are checked before a returned entry is allocated.
20
+ */
21
+ import { gunzipSync } from 'node:zlib';
22
+ const BLOCK = 512;
23
+ const ZERO_BLOCK = Buffer.alloc(BLOCK);
24
+ const UTF8_FATAL = new TextDecoder('utf-8', { fatal: true });
25
+ export const DEFAULT_TAR_LIMITS = {
26
+ maxCompressedBytes: 256 * 1024 * 1024,
27
+ maxExpandedBytes: 1024 * 1024 * 1024,
28
+ maxFileCount: 50_000,
29
+ maxFileBytes: 100 * 1024 * 1024,
30
+ maxPathLength: 1024,
31
+ };
32
+ /** Max length for an in-archive relative path we are willing to join and write. */
33
+ export const MAX_ARCHIVE_PATH_LENGTH = 1024;
34
+ /**
35
+ * Returns `undefined` if `relPath` is safe to `join()` under a destination
36
+ * directory, else a human-readable reason it must be rejected. This is
37
+ * reject-don't-normalize: an unnormalized archive name is refused outright,
38
+ * never canonicalized into a safe-looking path.
39
+ */
40
+ export function archivePathViolation(relPath) {
41
+ if (relPath === '')
42
+ return 'empty path';
43
+ if (relPath.includes('\0'))
44
+ return 'contains a NUL byte';
45
+ if (isAbsoluteArchivePath(relPath))
46
+ return 'is an absolute path';
47
+ // Split on both separators so `..\\` tricks cannot evade the check.
48
+ const segments = relPath.split(/[\\/]+/);
49
+ if (segments.some((s) => s === '.' || s === '..')) {
50
+ return "contains a '.' or '..' segment";
51
+ }
52
+ if (relPath.length > MAX_ARCHIVE_PATH_LENGTH) {
53
+ return `exceeds ${MAX_ARCHIVE_PATH_LENGTH}-char path length limit`;
54
+ }
55
+ return undefined;
56
+ }
57
+ /**
58
+ * The canonical `.wnlp` path policy. GitHub archive compatibility deliberately
59
+ * keeps using {@link archivePathViolation}; bundle paths add the portable rule
60
+ * that `/` is the only separator, so a backslash is rejected rather than being
61
+ * interpreted differently by POSIX and Windows filesystems.
62
+ */
63
+ export function canonicalBundlePathViolation(relPath) {
64
+ const violation = archivePathViolation(relPath);
65
+ if (violation !== undefined)
66
+ return violation;
67
+ if (relPath.includes('\\'))
68
+ return "contains a backslash; canonical bundle paths must use '/' separators";
69
+ return undefined;
70
+ }
71
+ /** Return the prior regular-file path that would have to be a directory for `path`. */
72
+ export function canonicalBundleFilePrefix(path, priorFilePaths) {
73
+ let slash = path.indexOf('/');
74
+ while (slash !== -1) {
75
+ const prefix = path.slice(0, slash);
76
+ if (priorFilePaths.has(prefix))
77
+ return prefix;
78
+ slash = path.indexOf('/', slash + 1);
79
+ }
80
+ return undefined;
81
+ }
82
+ /** POSIX-absolute, UNC-absolute, or Windows-drive-absolute path test. */
83
+ function isAbsoluteArchivePath(relPath) {
84
+ return /^[\\/]/.test(relPath) || /^[A-Za-z]:/.test(relPath);
85
+ }
86
+ /**
87
+ * Bounded gzip inflation. The compressed-size check happens before zlib sees
88
+ * the input, and `maxOutputLength` caps expansion itself.
89
+ */
90
+ export function inflateArchive(bytes, limits) {
91
+ if (bytes.length > limits.maxCompressedBytes) {
92
+ throw new Error(`compressed archive size ${bytes.length} exceeds limit of ${limits.maxCompressedBytes} bytes`);
93
+ }
94
+ try {
95
+ return gunzipSync(bytes, { maxOutputLength: limits.maxExpandedBytes });
96
+ }
97
+ catch (e) {
98
+ if (e.code === 'ERR_BUFFER_TOO_LARGE') {
99
+ throw new Error(`expanded archive size exceeds limit of ${limits.maxExpandedBytes} bytes`);
100
+ }
101
+ throw e;
102
+ }
103
+ }
104
+ /** A strict-policy archive violation with machine-readable detail. */
105
+ export class ArchiveViolation extends Error {
106
+ code;
107
+ entryPath;
108
+ typeflag;
109
+ constructor(code, message, detail) {
110
+ super(message);
111
+ this.name = 'ArchiveViolation';
112
+ this.code = code;
113
+ if (detail?.entryPath !== undefined)
114
+ this.entryPath = detail.entryPath;
115
+ if (detail?.typeflag !== undefined)
116
+ this.typeflag = detail.typeflag;
117
+ }
118
+ }
119
+ /** Parse a NUL/space-padded octal field (historical compatible behavior). */
120
+ function parseOctal(bytes) {
121
+ let s = '';
122
+ for (const b of bytes) {
123
+ if (b === 0 || b === 32)
124
+ continue;
125
+ s += String.fromCharCode(b);
126
+ }
127
+ return s.length ? parseInt(s, 8) : 0;
128
+ }
129
+ function isOctalField(bytes) {
130
+ for (const b of bytes) {
131
+ if (b === 0 || b === 32)
132
+ continue;
133
+ if (b < 0x30 || b > 0x37)
134
+ return false;
135
+ }
136
+ return true;
137
+ }
138
+ function canonicalOctalField(value, width) {
139
+ const digits = value.toString(8);
140
+ if (digits.length > width - 1)
141
+ return Buffer.alloc(0);
142
+ return Buffer.from(`${digits.padStart(width - 1, '0')}\0`, 'ascii');
143
+ }
144
+ function fieldEquals(actual, expected) {
145
+ return actual.length === expected.length && actual.every((b, i) => b === expected[i]);
146
+ }
147
+ /**
148
+ * The deterministic USTAR name placeholder paired with a canonical PAX path.
149
+ * The writer uses the first 100 UTF-8 bytes when that slice ends on a
150
+ * character boundary; otherwise it uses the fixed ASCII `PaxData` marker.
151
+ */
152
+ export function canonicalPaxNamePlaceholder(path) {
153
+ const rawPath = Buffer.from(path, 'utf8');
154
+ const prefixBytes = rawPath.subarray(0, 100);
155
+ const prefix = Buffer.from(prefixBytes).toString('utf8');
156
+ const prefixField = Buffer.from(prefix, 'utf8');
157
+ return prefixField.length === prefixBytes.length ? prefix : 'PaxData';
158
+ }
159
+ function readCStringCompatible(bytes) {
160
+ const nul = bytes.indexOf(0);
161
+ const slice = nul >= 0 ? bytes.subarray(0, nul) : bytes;
162
+ return Buffer.from(slice).toString('utf8');
163
+ }
164
+ function readCStringStrict(bytes, label) {
165
+ const nul = bytes.indexOf(0);
166
+ const slice = nul >= 0 ? bytes.subarray(0, nul) : bytes;
167
+ // Canonical USTAR fields are NUL padded; bytes after the first NUL are not
168
+ // meaningful and must not contain hidden alternate names.
169
+ if (nul >= 0 && bytes.subarray(nul + 1).some((b) => b !== 0)) {
170
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', `${label} field contains non-zero bytes after its NUL terminator`);
171
+ }
172
+ try {
173
+ return UTF8_FATAL.decode(slice);
174
+ }
175
+ catch {
176
+ throw new ArchiveViolation('ARCHIVE_PATH_VIOLATION', `${label} field is not valid UTF-8`);
177
+ }
178
+ }
179
+ function readAsciiStrict(bytes, label) {
180
+ for (const b of bytes) {
181
+ if (b > 0x7f) {
182
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', `${label} field contains non-ASCII bytes`);
183
+ }
184
+ }
185
+ return Buffer.from(bytes).toString('ascii');
186
+ }
187
+ /**
188
+ * Parse PAX records using byte lengths. PAX record lengths count bytes, not
189
+ * JavaScript UTF-16 code units, so this implementation remains correct for a
190
+ * UTF-8 path containing multi-byte characters.
191
+ */
192
+ function parsePaxRecordsStrict(data) {
193
+ if (data.length === 0) {
194
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', 'pax extended header has an empty data block');
195
+ }
196
+ const records = [];
197
+ let offset = 0;
198
+ while (offset < data.length) {
199
+ const space = data.indexOf(0x20, offset);
200
+ if (space < 0) {
201
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: missing length separator`);
202
+ }
203
+ const lenBytes = data.subarray(offset, space);
204
+ const lenText = readAsciiStrict(lenBytes, 'pax length');
205
+ if (!/^[0-9]+$/.test(lenText)) {
206
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: length '${lenText}' is not decimal`);
207
+ }
208
+ // Canonical writer output has no leading zeroes and a self-consistent
209
+ // decimal length. Refusing a non-canonical representation keeps the bytes
210
+ // unambiguous even when stock tar accepts the record.
211
+ if (String(Number(lenText)) !== lenText || !Number.isSafeInteger(Number(lenText))) {
212
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: invalid length '${lenText}'`);
213
+ }
214
+ const length = Number(lenText);
215
+ const remaining = data.length - offset;
216
+ if (length < lenText.length + 4 || length > remaining) {
217
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: length ${length} is out of range`);
218
+ }
219
+ const record = data.subarray(offset, offset + length);
220
+ if (record[length - 1] !== 0x0a) {
221
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: missing trailing newline`);
222
+ }
223
+ const body = record.subarray(space - offset + 1, length - 1);
224
+ const equals = body.indexOf(0x3d);
225
+ if (equals <= 0) {
226
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: missing key or '='`);
227
+ }
228
+ const key = readAsciiStrict(body.subarray(0, equals), 'pax key');
229
+ if (key.length === 0) {
230
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: empty key`);
231
+ }
232
+ let value;
233
+ try {
234
+ value = UTF8_FATAL.decode(body.subarray(equals + 1));
235
+ }
236
+ catch {
237
+ throw new ArchiveViolation('ARCHIVE_BAD_PAX', `malformed pax record at byte ${offset}: value is not valid UTF-8`);
238
+ }
239
+ records.push({ key, value });
240
+ offset += length;
241
+ }
242
+ return records;
243
+ }
244
+ /** Compatible PAX parsing: malformed records are ignored like the old reader. */
245
+ function parsePaxRecordsLenient(data) {
246
+ const out = new Map();
247
+ let offset = 0;
248
+ while (offset < data.length) {
249
+ const space = data.indexOf(0x20, offset);
250
+ if (space < 0)
251
+ break;
252
+ const lenText = Buffer.from(data.subarray(offset, space)).toString('ascii');
253
+ const length = Number.parseInt(lenText, 10);
254
+ if (!Number.isFinite(length) || length <= 0 || offset + length > data.length)
255
+ break;
256
+ const record = data.subarray(offset, offset + length);
257
+ if (record[length - 1] !== 0x0a)
258
+ break;
259
+ const body = record.subarray(space - offset + 1, length - 1);
260
+ const equals = body.indexOf(0x3d);
261
+ if (equals > 0) {
262
+ const key = Buffer.from(body.subarray(0, equals)).toString('utf8');
263
+ const value = Buffer.from(body.subarray(equals + 1)).toString('utf8');
264
+ out.set(key, value);
265
+ }
266
+ offset += length;
267
+ }
268
+ return out;
269
+ }
270
+ function assertCanonicalHeaderFields(header, storedChecksum, paxPath) {
271
+ const checksumField = header.subarray(148, 156);
272
+ if (checksumField[6] !== 0 || checksumField[7] !== 0x20 || !/^[0-7]{6}$/.test(Buffer.from(checksumField.subarray(0, 6)).toString('ascii'))) {
273
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', 'tar checksum field is not canonical');
274
+ }
275
+ if (!fieldEquals(header.subarray(257, 263), Buffer.from('ustar\0', 'ascii'))) {
276
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', "tar magic must be 'ustar\\0'");
277
+ }
278
+ if (!fieldEquals(header.subarray(263, 265), Buffer.from('00', 'ascii'))) {
279
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', "tar version must be '00'");
280
+ }
281
+ // Canonical regular and PAX headers do not carry links, devices, or a
282
+ // prefix field. A long path is represented by a PAX path record instead of
283
+ // the USTAR prefix field in the production writer.
284
+ if (header.subarray(157, 257).some((b) => b !== 0)) {
285
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', 'tar linkname field must be empty');
286
+ }
287
+ if (paxPath !== undefined) {
288
+ const expected = Buffer.alloc(100);
289
+ Buffer.from(canonicalPaxNamePlaceholder(paxPath), 'utf8').copy(expected);
290
+ if (!fieldEquals(header.subarray(0, 100), expected)) {
291
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', `tar name field is not the canonical PAX placeholder for '${paxPath}'`);
292
+ }
293
+ }
294
+ if (header.subarray(329, 500).some((b) => b !== 0)) {
295
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', 'tar device or prefix fields must be empty');
296
+ }
297
+ if (header.subarray(500, 512).some((b) => b !== 0)) {
298
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', 'tar reserved header bytes must be zero');
299
+ }
300
+ const canonical = canonicalOctalField(storedChecksum, 8);
301
+ if (!fieldEquals(checksumField.subarray(0, 6), canonical.subarray(1, 7))) {
302
+ throw new ArchiveViolation('NON_CANONICAL_HEADER', 'tar checksum field is not zero-padded canonical octal');
303
+ }
304
+ }
305
+ function checksum(header) {
306
+ let sum = 0;
307
+ for (let i = 0; i < BLOCK; i++)
308
+ sum += i >= 148 && i < 156 ? 0x20 : header[i];
309
+ return sum;
310
+ }
311
+ function effectiveName(prefix, name) {
312
+ return prefix ? `${prefix}/${name}` : name;
313
+ }
314
+ /**
315
+ * Parse an UNCOMPRESSED tar stream. Compatible mode retains the historical
316
+ * extractor contract; strict mode accepts only canonical package archives.
317
+ */
318
+ export function parseTar(tar, limits, opts) {
319
+ const strict = opts.policy === 'strict';
320
+ const out = [];
321
+ let offset = 0;
322
+ let headerCount = 0;
323
+ let pendingPaxPath;
324
+ let lastPath;
325
+ const strictFilePaths = new Set();
326
+ const failCompat = (message) => {
327
+ throw new Error(message);
328
+ };
329
+ const failStrict = (code, message, detail) => {
330
+ throw new ArchiveViolation(code, message, detail);
331
+ };
332
+ while (true) {
333
+ if (offset + BLOCK > tar.length) {
334
+ if (strict) {
335
+ failStrict('ARCHIVE_TRUNCATED', offset < tar.length
336
+ ? `archive ends mid-block at byte ${offset} (${tar.length - offset} trailing bytes)`
337
+ : 'archive is missing the two-zero-block terminator');
338
+ }
339
+ break;
340
+ }
341
+ const header = tar.subarray(offset, offset + BLOCK);
342
+ if (header.every((b) => b === 0)) {
343
+ if (!strict)
344
+ break;
345
+ if (pendingPaxPath !== undefined) {
346
+ failStrict('ARCHIVE_DANGLING_PAX', `pax extended header for path '${pendingPaxPath}' has no following entry`);
347
+ }
348
+ const remaining = tar.length - offset;
349
+ if (remaining < BLOCK * 2) {
350
+ failStrict('ARCHIVE_TRUNCATED', 'archive terminator must be two consecutive zero blocks');
351
+ }
352
+ const second = tar.subarray(offset + BLOCK, offset + BLOCK * 2);
353
+ if (!second.every((b) => b === 0)) {
354
+ failStrict('ARCHIVE_TRUNCATED', 'archive terminator must be two consecutive zero blocks');
355
+ }
356
+ if (remaining !== BLOCK * 2) {
357
+ failStrict('ARCHIVE_TRAILING_BYTES', `bytes follow the exact two-block archive terminator at byte ${offset + BLOCK * 2}`);
358
+ }
359
+ return out;
360
+ }
361
+ headerCount += 1;
362
+ if (headerCount > limits.maxFileCount) {
363
+ const message = `archive file count exceeds limit of ${limits.maxFileCount}`;
364
+ if (strict)
365
+ failStrict('ARCHIVE_TOO_MANY_ENTRIES', message);
366
+ failCompat(message);
367
+ }
368
+ const typeflag = String.fromCharCode(header[156] ?? 0);
369
+ if (strict) {
370
+ if (!isOctalField(header.subarray(148, 156))) {
371
+ failStrict('ARCHIVE_BAD_CHECKSUM', 'tar header checksum field is not valid octal');
372
+ }
373
+ const stored = parseOctal(header.subarray(148, 156));
374
+ const computed = checksum(header);
375
+ if (stored !== computed) {
376
+ failStrict('ARCHIVE_BAD_CHECKSUM', `tar header checksum mismatch (stored ${stored}, computed ${computed})`);
377
+ }
378
+ assertCanonicalHeaderFields(header, stored, (typeflag === '0' || typeflag === '\0') ? pendingPaxPath : undefined);
379
+ for (const [label, start, end] of [
380
+ ['mode', 100, 108],
381
+ ['uid', 108, 116],
382
+ ['gid', 116, 124],
383
+ ['size', 124, 136],
384
+ ['mtime', 136, 148],
385
+ ]) {
386
+ const field = header.subarray(start, end);
387
+ if (!isOctalField(field)) {
388
+ failStrict('ARCHIVE_BAD_OCTAL', `tar header '${label}' field is not valid octal`);
389
+ }
390
+ const value = parseOctal(field);
391
+ if (!fieldEquals(field, canonicalOctalField(value, end - start))) {
392
+ failStrict('NON_CANONICAL_HEADER', `tar header '${label}' field is not canonical`);
393
+ }
394
+ }
395
+ }
396
+ const nameField = strict
397
+ ? readCStringStrict(header.subarray(0, 100), 'tar name')
398
+ : readCStringCompatible(header.subarray(0, 100));
399
+ const prefixField = strict
400
+ ? readCStringStrict(header.subarray(345, 500), 'tar prefix')
401
+ : readCStringCompatible(header.subarray(345, 500));
402
+ const unameField = strict
403
+ ? readCStringStrict(header.subarray(265, 297), 'tar uname')
404
+ : readCStringCompatible(header.subarray(265, 297));
405
+ const gnameField = strict
406
+ ? readCStringStrict(header.subarray(297, 329), 'tar gname')
407
+ : readCStringCompatible(header.subarray(297, 329));
408
+ const sizeField = parseOctal(header.subarray(124, 136));
409
+ const modeField = parseOctal(header.subarray(100, 108));
410
+ const uidField = parseOctal(header.subarray(108, 116));
411
+ const gidField = parseOctal(header.subarray(116, 124));
412
+ const mtimeField = parseOctal(header.subarray(136, 148));
413
+ if (!Number.isInteger(sizeField) || sizeField < 0) {
414
+ const message = `corrupt tar header: invalid size field (got ${sizeField})`;
415
+ if (strict)
416
+ failStrict('ARCHIVE_BAD_OCTAL', message, { entryPath: nameField });
417
+ failCompat(message);
418
+ }
419
+ offset += BLOCK;
420
+ const dataStart = offset;
421
+ const dataEnd = dataStart + sizeField;
422
+ const paddedEnd = dataEnd + ((BLOCK - (sizeField % BLOCK)) % BLOCK);
423
+ if (dataEnd > tar.length || paddedEnd > tar.length) {
424
+ const message = `corrupt tar archive: entry data (${sizeField} bytes) extends past end of archive`;
425
+ if (strict)
426
+ failStrict('ARCHIVE_TRUNCATED', message, { entryPath: nameField });
427
+ failCompat(message);
428
+ }
429
+ if (strict && tar.subarray(dataEnd, paddedEnd).some((b) => b !== 0)) {
430
+ failStrict('NON_CANONICAL_HEADER', 'tar entry data padding must be zero', { entryPath: nameField });
431
+ }
432
+ const data = tar.subarray(dataStart, dataEnd);
433
+ offset = paddedEnd;
434
+ if (typeflag === 'x') {
435
+ if (strict) {
436
+ if (nameField !== 'PaxHeader') {
437
+ failStrict('NON_CANONICAL_HEADER', `pax extended header name must be 'PaxHeader' (got '${nameField}')`);
438
+ }
439
+ if (modeField !== 0o644 || uidField !== 0 || gidField !== 0 || mtimeField !== 0 || unameField !== '' || gnameField !== '') {
440
+ failStrict('NON_CANONICAL_HEADER', 'pax extended header must use mode 0644, uid/gid 0, mtime 0, empty uname/gname');
441
+ }
442
+ if (pendingPaxPath !== undefined) {
443
+ failStrict('ARCHIVE_DANGLING_PAX', `pax extended header for path '${pendingPaxPath}' has no following entry`);
444
+ }
445
+ const records = parsePaxRecordsStrict(data);
446
+ if (records.length !== 1 || records[0].key !== 'path') {
447
+ failStrict('ARCHIVE_BAD_PAX', `bundle pax extended header must carry exactly one 'path' record (got ${records.map((r) => r.key).join(', ') || 'none'})`);
448
+ }
449
+ const p = records[0].value;
450
+ if (p === '')
451
+ failStrict('ARCHIVE_BAD_PAX', "pax 'path' record is empty");
452
+ pendingPaxPath = p;
453
+ continue;
454
+ }
455
+ const records = parsePaxRecordsLenient(data);
456
+ const p = records.get('path');
457
+ if (p !== undefined)
458
+ pendingPaxPath = p;
459
+ continue;
460
+ }
461
+ const rawName = effectiveName(prefixField, nameField);
462
+ const candidateName = pendingPaxPath ?? rawName;
463
+ if (candidateName) {
464
+ if (candidateName.length > limits.maxPathLength) {
465
+ const message = `archive entry path length ${candidateName.length} exceeds limit of ${limits.maxPathLength} chars`;
466
+ if (strict)
467
+ failStrict('ARCHIVE_PATH_TOO_LONG', message, { entryPath: candidateName });
468
+ failCompat(message);
469
+ }
470
+ if (strict) {
471
+ const violation = canonicalBundlePathViolation(candidateName);
472
+ if (violation) {
473
+ const message = `unsafe archive path '${candidateName}': ${violation}`;
474
+ failStrict('ARCHIVE_PATH_VIOLATION', message, { entryPath: candidateName });
475
+ }
476
+ }
477
+ }
478
+ if (typeflag === '5') {
479
+ if (strict) {
480
+ failStrict('UNSUPPORTED_ENTRY_TYPE', 'bundle entries must be regular files; got a directory entry', {
481
+ entryPath: pendingPaxPath ?? rawName,
482
+ typeflag: '5',
483
+ });
484
+ }
485
+ continue;
486
+ }
487
+ if (typeflag === 'g') {
488
+ if (strict) {
489
+ failStrict('UNSUPPORTED_ENTRY_TYPE', 'bundle entries must be regular files; got a pax global extended header', { typeflag: 'g' });
490
+ }
491
+ continue;
492
+ }
493
+ if (typeflag !== '0' && typeflag !== '\0') {
494
+ if (strict) {
495
+ failStrict('UNSUPPORTED_ENTRY_TYPE', `bundle entries must be regular files; got typeflag '${typeflag}'`, {
496
+ entryPath: pendingPaxPath ?? rawName,
497
+ typeflag,
498
+ });
499
+ }
500
+ pendingPaxPath = undefined;
501
+ continue;
502
+ }
503
+ if (strict && typeflag !== '0') {
504
+ failStrict('NON_CANONICAL_HEADER', 'canonical regular files must use typeflag 0', {
505
+ entryPath: pendingPaxPath ?? rawName,
506
+ typeflag,
507
+ });
508
+ }
509
+ if (sizeField > limits.maxFileBytes) {
510
+ const message = `archive entry exceeds per-file size limit of ${limits.maxFileBytes} bytes (${sizeField} bytes)`;
511
+ if (strict)
512
+ failStrict('ARCHIVE_ENTRY_TOO_LARGE', message, { entryPath: pendingPaxPath ?? rawName });
513
+ failCompat(message);
514
+ }
515
+ const name = pendingPaxPath ?? rawName;
516
+ const hadPaxPath = pendingPaxPath !== undefined;
517
+ pendingPaxPath = undefined;
518
+ if (strict) {
519
+ if (name.length > limits.maxPathLength) {
520
+ failStrict('ARCHIVE_PATH_TOO_LONG', `archive entry path length ${name.length} exceeds limit of ${limits.maxPathLength} chars`, { entryPath: name.slice(0, 128) });
521
+ }
522
+ const violation = canonicalBundlePathViolation(name);
523
+ if (violation) {
524
+ failStrict('ARCHIVE_PATH_VIOLATION', `unsafe archive path '${name}': ${violation}`, { entryPath: name });
525
+ }
526
+ if (!name || name.endsWith('/')) {
527
+ failStrict('ARCHIVE_PATH_VIOLATION', `unsafe archive path '${name}': directory-like names are not regular files`, { entryPath: name });
528
+ }
529
+ if (modeField !== 0o644 && modeField !== 0o755) {
530
+ failStrict('NON_CANONICAL_HEADER', `bundle entry '${name}' must use mode 0644 or 0755 (got 0${modeField.toString(8)})`, { entryPath: name });
531
+ }
532
+ if (uidField !== 0 || gidField !== 0 || mtimeField !== 0 || unameField !== '' || gnameField !== '') {
533
+ failStrict('NON_CANONICAL_HEADER', `bundle entry '${name}' must use uid/gid 0, mtime 0, empty uname/gname`, { entryPath: name });
534
+ }
535
+ if (lastPath !== undefined) {
536
+ const order = Buffer.compare(Buffer.from(lastPath, 'utf8'), Buffer.from(name, 'utf8'));
537
+ if (order === 0) {
538
+ failStrict('ARCHIVE_DUPLICATE_PATH', `duplicate archive path '${name}'`, { entryPath: name });
539
+ }
540
+ if (order > 0) {
541
+ failStrict('NON_CANONICAL_HEADER', `archive entries are not sorted by UTF-8 path: '${name}' follows '${lastPath}'`, { entryPath: name });
542
+ }
543
+ }
544
+ const filePrefix = canonicalBundleFilePrefix(name, strictFilePaths);
545
+ if (filePrefix !== undefined) {
546
+ failStrict('ARCHIVE_PATH_PREFIX_COLLISION', `archive file path '${filePrefix}' is a complete-segment prefix of '${name}'`, { entryPath: name });
547
+ }
548
+ strictFilePaths.add(name);
549
+ lastPath = name;
550
+ out.push({
551
+ path: name,
552
+ size: sizeField,
553
+ mode: modeField,
554
+ uid: uidField,
555
+ gid: gidField,
556
+ uname: unameField,
557
+ gname: gnameField,
558
+ mtime: mtimeField,
559
+ typeflag: '0',
560
+ hadPaxPath,
561
+ data: new Uint8Array(data),
562
+ });
563
+ continue;
564
+ }
565
+ if (name) {
566
+ if (name.length > limits.maxPathLength) {
567
+ failCompat(`archive entry path length ${name.length} exceeds limit of ${limits.maxPathLength} chars`);
568
+ }
569
+ out.push({
570
+ path: name,
571
+ size: sizeField,
572
+ mode: modeField,
573
+ uid: uidField,
574
+ gid: gidField,
575
+ uname: unameField,
576
+ gname: gnameField,
577
+ mtime: mtimeField,
578
+ typeflag: '0',
579
+ hadPaxPath,
580
+ data: new Uint8Array(data),
581
+ });
582
+ }
583
+ }
584
+ if (strict) {
585
+ if (pendingPaxPath !== undefined) {
586
+ failStrict('ARCHIVE_DANGLING_PAX', `pax extended header for path '${pendingPaxPath}' has no following entry`);
587
+ }
588
+ failStrict('ARCHIVE_TRUNCATED', 'archive is missing the two-zero-block terminator');
589
+ }
590
+ return out;
591
+ }