{"record":{"id":"c115de2b60e42c16","repo":"can1357/oh-my-pi","slug":"invalid-tar-pax-record","errorCode":null,"errorMessage":"Invalid tar PAX record","messagePattern":"Invalid tar PAX record","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/tar.ts","lineNumber":182,"sourceCode":"\tlet signed = 0;\n\tfor (let index = 0; index < BLOCK_SIZE; index++) {\n\t\tconst inChecksum = index >= CHECKSUM_OFFSET && index < CHECKSUM_OFFSET + CHECKSUM_LENGTH;\n\t\tconst byte = inChecksum ? 0x20 : (buffer[offset + index] ?? 0);\n\t\tunsigned += byte;\n\t\tsigned += (byte << 24) >> 24;\n\t}\n\treturn stored === unsigned || stored === signed;\n}\n\nfunction parsePaxRecords(data: Uint8Array, limits: ArchiveLimits): Map<string, string> {\n\tassertIndexSize(data.byteLength, limits, \"tar PAX metadata\");\n\tconst attrs = new Map<string, string>();\n\tlet pos = 0;\n\twhile (pos < data.byteLength) {\n\t\tlet space = pos;\n\t\twhile (space < data.byteLength && data[space] !== 0x20) space++;\n\t\tif (space === pos || space >= data.byteLength || space - pos > 16) {\n\t\t\tthrow new ArchiveError(\"Invalid tar PAX record\");\n\t\t}\n\t\tlet length = 0;\n\t\tfor (let index = pos; index < space; index++) {\n\t\t\tconst byte = data[index]!;\n\t\t\tif (byte < 0x30 || byte > 0x39) throw new ArchiveError(\"Invalid tar PAX record\");\n\t\t\tlength = length * 10 + (byte - 0x30);\n\t\t\tif (length > data.byteLength - pos) throw new ArchiveError(\"Invalid tar PAX record\");\n\t\t}\n\t\tif (length <= 0 || pos + length > data.byteLength || data[pos + length - 1] !== 0x0a) {\n\t\t\tthrow new ArchiveError(\"Invalid tar PAX record\");\n\t\t}\n\t\tconst record = data.subarray(space + 1, pos + length - 1);\n\t\tconst equals = record.indexOf(0x3d);\n\t\tif (equals >= 0) {\n\t\t\tconst key = record.subarray(0, equals);\n\t\t\tconst value = record.subarray(equals + 1);\n\t\t\tif (bytesMatchAscii(key, 0, PAX_SPARSE_MARKER)) {\n\t\t\t\tattrs.set(PAX_SPARSE_MARKER, value.byteLength === 0 ? \"\" : \"1\");","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/tar.ts#L164-L200","documentation":"parsePaxRecords splits PAX extended-header data into '<length> <key>=<value>\\n' records. This throw fires while reading the leading length token: there is no space after a non-empty token, the token is longer than 16 digits, or the record starts with a space. A well-formed PAX blob always begins each record with a decimal length followed by a space.","triggerScenarios":"Typeflag 'x'/'g' member whose payload does not start with `<digits> ` — e.g. payload begins with '=' (empty length), or a run of >16 non-space bytes — encountered while indexing via readTar/readTarEntriesFromBuffer.","commonSituations":"Corrupted archives, archives where PAX payload was truncated or shifted by an earlier bad size, or bytes that are not really PAX data being interpreted as such because a header typeflag was damaged.","solutions":["Verify archive integrity — this error usually means the PAX member bytes are corrupt or misaligned.","Check the preceding header's size field: a wrong size there shifts data alignment and breaks PAX parsing.","Regenerate the archive with GNU tar/bsdtar if a custom writer emitted it.","Catch ArchiveError and reject the archive; PAX records cannot be partially recovered."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// PAX payload must start with '<digits> ' per record\nfunction looksLikePaxPayload(data: Uint8Array): boolean {\n  const first = data[0];\n  if (first === undefined || first === 0x20) return false; // empty/leading-space length\n  return first >= 0x30 && first <= 0x39;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const entries = readTarEntriesFromBuffer(buffer, options);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message === \"Invalid tar PAX record\") {\n    throw new Error(\"PAX extended header payload is malformed or misaligned\");\n  }\n  throw err;\n}","preventionTips":["Verify archives with a reference tool (tar -tvf) before programmatic parsing.","Keep the format module's limits intact — truncated PAX payloads usually stem from earlier corruption.","Regenerate archives with standard tooling rather than hand-patching bytes.","If you write PAX headers, include the length prefix and space in the record length."],"tags":["tar","pax","archive","malformed-data"],"backgroundTag":"corrupt-tar-archive","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}