{"record":{"id":"908843ef6ac9592a","repo":"can1357/oh-my-pi","slug":"invalid-lzh-common-header-crc-16","errorCode":null,"errorMessage":"Invalid LZH common header CRC-16","messagePattern":"Invalid LZH common header CRC-16","errorType":"validation","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/lzh.ts","lineNumber":570,"sourceCode":"\t\t\t}\n\t\t\tprocessExtendedHeader(type, data, cursor + 3, fields);\n\t\t\tcursor += extensionSize;\n\t\t}\n\t\tif (cursor !== headerEnd) throw new ArchiveError(\"Invalid LZH level-2 extended header chain\");\n\t\tdataStart = headerEnd;\n\t\tpackedSize = fields.packedSize ?? packedSize;\n\t}\n\tif (level === 1 && osId === 0x20 && method === \"-lh7-\") {\n\t\tthrow new ArchiveError(\"LZH uses the incompatible LHARK -lh7- variant\");\n\t}\n\n\tsize = fields.size ?? size;\n\tmtimeMs = fields.mtimeMs ?? mtimeMs;\n\tconst mode = fields.mode;\n\tif (fields.commonCrc !== undefined) {\n\t\tconst relative = fields.commonCrcOffset! - offset;\n\t\tif (crc16WithZeroRange(bytes.subarray(offset, dataStart), relative, relative + 2) !== fields.commonCrc) {\n\t\t\tthrow new ArchiveError(\"Invalid LZH common header CRC-16\");\n\t\t}\n\t}\n\tconst filename = fields.unicodeFilename ?? fields.filename ?? legacyFilename ?? \"\";\n\tconst directory = fields.unicodeDirectory ?? fields.directory ?? \"\";\n\tconst rawPath = `${directory}${directory && !/[\\\\/]$/.test(directory) ? \"/\" : \"\"}${filename}`;\n\tassertArchivePathString(rawPath, \"member path\", options.limits.maxPathBytes);\n\tassertArchiveMemberSize(size, rawPath || \"<unnamed>\", options.limits);\n\tassertRange(bytes, dataStart, dataStart + packedSize, \"member data\");\n\treturn {\n\t\tmethod,\n\t\tpackedSize,\n\t\tsize,\n\t\tdataStart,\n\t\tnextOffset: dataStart + packedSize,\n\t\tcrc,\n\t\tpath: normalizeArchiveEntryPath(rawPath),\n\t\tmtimeMs,\n\t\tmode,","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/lzh.ts#L552-L588","documentation":"Level-1 headers can carry a common header CRC-16 (an extended-header field with its offset into the header). The library recomputes the CRC-16 over the header with the CRC field zeroed and compares it. A mismatch means the header bytes were altered or the field/offset is inconsistent with the actual header layout.","triggerScenarios":"readLzh() on a level-1 archive whose extended headers advertise a common CRC (fields.commonCrc) that does not match the recomputed CRC-16 over the header region.","commonSituations":"Bit-rot or corruption of header bytes; tools that rewrite headers (e.g. renaming members) without updating the common CRC; hand-patched archives.","solutions":["Verify the file against its original checksum; re-download or re-extract if it differs.","Repack the archive with a standard LHA tool so the common CRC is regenerated over the current header bytes.","If a third-party tool modified the archive (rename/recompress), redo the operation with a tool that maintains LZH common CRCs.","Treat the archive as untrusted/corrupt and reject it rather than attempting extraction."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if ((await sha256File(path)) !== expectedSha256) throw new Error(\"archive modified or corrupt — refusing to parse\");","typeGuard":null,"tryCatchPattern":"try {\n  const entries = await readLzh(source, options);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message === \"Invalid LZH common header CRC-16\") {\n    throw new Error(\"archive header was modified or corrupt — restore from a verified copy\");\n  }\n  throw err;\n}","preventionTips":["Keep archives immutable after creation; never patch header bytes in place","Verify checksums before parsing","If renaming members, repack with a tool that updates LZH CRCs"],"tags":["archive","lzh","crc","integrity","corrupt-file"],"backgroundTag":"checksum-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}