{"record":{"id":"128addf63b4e7584","repo":"can1357/oh-my-pi","slug":"invalid-tar-member-size","errorCode":null,"errorMessage":"Invalid tar member size","messagePattern":"Invalid tar member size","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/tar.ts","lineNumber":136,"sourceCode":"\tlet value = 0n;\n\tif ((first & 0x80) !== 0) {\n\t\tvalue = BigInt(first & 0x7f);\n\t\tfor (let index = 1; index < length; index++) {\n\t\t\tvalue = (value << 8n) | BigInt(buffer[offset + index]!);\n\t\t}\n\t\tif ((first & 0x40) !== 0) value -= 1n << BigInt(length * 8 - 1);\n\t} else {\n\t\tfor (let index = 0; index < length; index++) {\n\t\t\tconst byte = buffer[offset + index]!;\n\t\t\tif (byte >= 0x30 && byte <= 0x37) value = value * 8n + BigInt(byte - 0x30);\n\t\t}\n\t}\n\treturn Number(value);\n}\n\nfunction readTarSize(buffer: Uint8Array, offset: number): number {\n\tconst size = readTarNumeric(buffer, offset, SIZE_LENGTH);\n\tif (!Number.isSafeInteger(size) || size < 0) throw new ArchiveError(\"Invalid tar member size\");\n\treturn size;\n}\n\nfunction paddedSize(size: number): number {\n\tconst remainder = size % BLOCK_SIZE;\n\tconst padded = size + (remainder === 0 ? 0 : BLOCK_SIZE - remainder);\n\tif (!Number.isSafeInteger(padded)) throw new ArchiveError(\"Invalid tar member size\");\n\treturn padded;\n}\n\nfunction parsePaxSize(value: string, field: string): number {\n\tif (!/^\\d+$/.test(value)) throw new ArchiveError(`Invalid tar ${field}`);\n\tconst size = Number(value);\n\tif (!Number.isSafeInteger(size) || size < 0) throw new ArchiveError(`Invalid tar ${field}`);\n\treturn size;\n}\n\nfunction isZeroBlock(buffer: Uint8Array, offset: number): boolean {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/tar.ts#L118-L154","documentation":"readTarSize decodes the 12-byte size field of a tar header and validates the result. This throw means the decoded value is not a non-negative safe integer — typically a corrupted, non-octal, or absurdly large size field (including base-256 values overflowing safe-integer range). The parser refuses sizes it cannot trust to slice member data safely.","triggerScenarios":"Parsing a tar header whose size field at offset 124 contains garbage (random bytes, ASCII text, or a base-256 encoded value exceeding Number.MAX_SAFE_INTEGER) — reached via the size accessor while indexing an archive with readTar/readTarEntriesFromBuffer.","commonSituations":"Corrupted downloads, files damaged in transfer/storage, misidentified files that pass a checksum by luck, or archives produced by broken/non-conforming tar writers.","solutions":["Verify the archive integrity (checksum, re-download, compare hashes) — this usually indicates real corruption.","Confirm the file is actually a tar archive; use sniffTar before parsing.","If you generate tar archives yourself, fix the writer: the size field must be zero-padded octal (e.g. '00000000000\\0') or valid GNU base-256.","Catch ArchiveError and report the archive as unrecoverable rather than retrying the same bytes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { sniffTar } from \"@oh-my-pi/pi-utils/ar/tar\";\n// pre-check: a header's size field must be octal digits or base-256\nconst sizeField = buffer.subarray(124, 136);\nconst looksOctal = [...sizeField].every(b => (b >= 0x30 && b <= 0x37) || b === 0 || b === 0x20);\nif (!sniffTar(buffer) || !looksOctal) throw new Error(\"Suspicious or corrupt tar size field\");","typeGuard":null,"tryCatchPattern":"try {\n  const entries = readTarEntriesFromBuffer(buffer, options);\n} catch (err) {\n  if (err instanceof ArchiveError && /Invalid tar member size/.test(err.message)) {\n    throw new Error(\"Archive is corrupt: member size field is not a valid octal/base-256 value\");\n  }\n  throw err;\n}","preventionTips":["Verify archive integrity (hash/checksum) before parsing untrusted files.","Reject files that fail sniffTar instead of forcing a parse.","If you write tar archives, test their output against GNU tar before shipping.","Treat this error as fatal corruption — never retry the same bytes."],"tags":["tar","archive","corrupt-data","integer-overflow"],"backgroundTag":"corrupt-tar-archive","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}