{"record":{"id":"279052d064f71d91","repo":"can1357/oh-my-pi","slug":"invalid-tar-octal-value-value","errorCode":null,"errorMessage":"Invalid tar octal value: ${value}","messagePattern":"Invalid tar octal value: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/natives/native/loader-state.js","lineNumber":449,"sourceCode":"\t\t\tnull\n\t\t);\n\t}\n\treturn embeddedAddon.files.find(file => file.variant === \"baseline\") || null;\n}\n\nfunction readTarString(buffer, offset, length) {\n\tconst end = Math.min(offset + length, buffer.length);\n\tlet stringEnd = offset;\n\twhile (stringEnd < end && buffer[stringEnd] !== 0) stringEnd++;\n\treturn buffer.toString(\"utf8\", offset, stringEnd);\n}\n\nfunction readTarOctal(buffer, offset, length) {\n\tconst value = readTarString(buffer, offset, length).trim();\n\tif (!value) return 0;\n\tconst parsed = Number.parseInt(value, 8);\n\tif (!Number.isFinite(parsed)) {\n\t\tthrow new Error(`Invalid tar octal value: ${value}`);\n\t}\n\treturn parsed;\n}\n\nfunction isZeroTarBlock(buffer, offset) {\n\tfor (let index = 0; index < 512; index++) {\n\t\tif (buffer[offset + index] !== 0) return false;\n\t}\n\treturn true;\n}\n\nfunction getTarEntryName(header) {\n\tconst name = readTarString(header, 0, 100);\n\tconst prefix = readTarString(header, 345, 155);\n\treturn prefix ? `${prefix}/${name}` : name;\n}\n\nfunction isSafeEmbeddedAddonFilename(filename) {","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/natives/native/loader-state.js#L431-L467","documentation":"readTarOctal() reads a tar header field as a NUL-padded octal ASCII string and parses it with parseInt(value, 8). If the field contains characters that are not valid octal (so the parse yields NaN/Infinity), it throws this error naming the raw value. This indicates the buffer is not a well-formed tar header at the expected offset.","triggerScenarios":"Calling readTarOctal(buffer, offset, length) on a buffer whose field at offset contains non-octal text — e.g. GNU tar base-256 (binary) size encoding for files >8GB, a non-tar file, or a misaligned offset.","commonSituations":"Extracting archives with entries larger than 8 GiB (old-style octal fields can't represent them so writers use base-256), parsing a gzip stream without decompressing first, reading a truncated/corrupted archive, or hard-coded offsets that don't match the header layout.","solutions":["Recreate the archive with `tar --format=ustar -cf` so all fields fit standard octal encoding.","Handle GNU base-256 fields: if the high bit of the first byte is set, decode the binary number instead of octal text.","Verify the input is a decompressed tar: gunzip first and check the 512-byte header + 'ustar' magic at offset 257.","Confirm offsets/lengths against the tar header layout (size at 124, mtime at 136, etc.)."],"exampleFix":"// before\nconst parsed = Number.parseInt(value, 8);\nif (!Number.isFinite(parsed)) throw new Error(`Invalid tar octal value: ${value}`);\n// after\nfunction readNumericField(buffer, offset, length) {\n  if (buffer[offset] & 0x80) {\n    // GNU base-256 encoding (large files)\n    let result = buffer[offset] & 0x7f;\n    for (let i = offset + 1; i < offset + length; i++) result = result * 256 + buffer[i];\n    return result;\n  }\n  const value = readTarString(buffer, offset, length).trim();\n  if (!value) return 0;\n  const parsed = Number.parseInt(value, 8);\n  if (!Number.isFinite(parsed)) throw new Error(`Invalid tar octal value: ${value}`);\n  return parsed;\n}","handlingStrategy":"validation","validationCode":"function isTarBuffer(buf) {\n  return buf.length >= 512 && buf.subarray(257, 262).toString('utf8') === 'ustar';\n}\nfunction usesBase256(buf, offset) {\n  return (buf[offset] & 0x80) !== 0; // GNU binary numeric field\n}\nif (!isTarBuffer(buffer)) throw new Error('Not a tar archive (missing ustar magic)');\nif (usesBase256(buffer, 124)) throw new Error('Entry uses GNU base-256 size; decode binary field');","typeGuard":"function isOctalField(buf, offset, length) {\n  for (let i = offset; i < offset + length; i++) {\n    const b = buf[i];\n    if (b === 0) return true;\n    if (b < 0x30 || b > 0x37) return false;\n  }\n  return true;\n}","tryCatchPattern":"try {\n  const size = readTarOctal(header, 124, 12);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Invalid tar octal value')) {\n    // likely GNU base-256 encoding (huge file) or bad offset — decode binary field\n    const size = readBase256(header, 124, 12);\n  } else throw err;\n}","preventionTips":["Create archives with --format=ustar to keep all fields octal-representable","Gunzip before parsing — never feed compressed bytes to a tar parser","Check the 'ustar' magic at offset 257 before reading header fields","Handle GNU base-256 numeric fields for entries larger than 8 GiB"],"tags":["tar","parsing","archive","octal","corruption"],"backgroundTag":"invalid-tar-header","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}