{"record":{"id":"137fad629da82ff4","repo":"can1357/oh-my-pi","slug":"invalid-lzh-compression-method-method","errorCode":null,"errorMessage":"Invalid LZH compression method '${method}'","messagePattern":"Invalid LZH compression method '(.+?)'","errorType":"validation","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/lzh.ts","lineNumber":466,"sourceCode":"\ninterface ParsedLzhHeader {\n\tmethod: string;\n\tpackedSize: number;\n\tsize: number;\n\tdataStart: number;\n\tnextOffset: number;\n\tcrc: number;\n\tpath?: string;\n\tmtimeMs?: number;\n\tmode?: number;\n}\n\nfunction parseLzhHeader(bytes: Uint8Array, offset: number, options: FormatReadOptions): ParsedLzhHeader {\n\tassertRange(bytes, offset, offset + 22, \"header\");\n\tconst level = bytes[offset + 20]!;\n\tif (level > 2) throw new ArchiveError(`Unsupported LZH header level ${level}`);\n\tconst method = String.fromCharCode(...bytes.subarray(offset + 2, offset + 7));\n\tif (!LHA_METHOD_PATTERN.test(method)) throw new ArchiveError(`Invalid LZH compression method '${method}'`);\n\tlet packedSize = u32(bytes, offset + 7);\n\tlet size = u32(bytes, offset + 11);\n\tlet crc = 0;\n\tlet legacyFilename: string | undefined;\n\tlet mtimeMs: number | undefined;\n\tlet osId = 0;\n\tlet dataStart: number;\n\tconst fields: LzhExtendedFields = {};\n\n\tif (level < 2) {\n\t\tconst headerLength = bytes[offset]!;\n\t\tconst minimum = level === 0 ? 22 : 25;\n\t\tif (headerLength < minimum) throw new ArchiveError(`Invalid LZH level-${level} header size`);\n\t\tconst baseEnd = offset + headerLength + 2;\n\t\tassertRange(bytes, offset, baseEnd, \"header\");\n\t\tlet sum = 0;\n\t\tfor (let index = offset + 2; index < baseEnd; index++) sum = (sum + bytes[index]!) & 0xff;\n\t\tif (sum !== bytes[offset + 1]) throw new ArchiveError(\"Invalid LZH header checksum\");","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/lzh.ts#L448-L484","documentation":"Thrown when the 5-byte compression method string in an LZH header (bytes offset+2..offset+7, e.g. -lh5-) fails the LHA_METHOD_PATTERN validation. The bytes do not form a recognized LHA method signature, so the region is not a valid LZH member header.","triggerScenarios":"Parsing a file that is not LZH (wrong magic), an offset that has drifted due to earlier misparsing, or a corrupted header region.","commonSituations":"Opening a file with an .lzh extension that is actually another format, parsing concatenated archives where a member boundary was computed wrong, or bit rot in the header.","solutions":["Verify the file is a genuine LHA archive (bytes 2-6 should look like -lhN- or -lzN-)","Re-obtain the archive from a known-good source","Check that you are not feeding a nested offset from a previous parse error"],"exampleFix":"// before: assuming .lzh extension means LZH\nconst archive = lzhRead(await Bun.file(name).arrayBuffer());\n// after: sniff the method signature\nconst sig = String.fromCharCode(...new Uint8Array(buf, 2, 5));\nif (!sig.startsWith('-') || !sig.endsWith('-')) throw new Error(`${name} is not LZH`);\nconst archive = lzhRead(buf);","handlingStrategy":"validation","validationCode":"const sig = String.fromCharCode(...bytes.subarray(2, 7));\nif (!/^-(lh|lz)[0-9a-z]-$/i.test(sig)) throw new Error('not LZH');","typeGuard":null,"tryCatchPattern":"try { parse(); } catch (err) { if (err instanceof ArchiveError) reject(err.message); else throw err; }","preventionTips":["Signature-sniff all archive inputs","Keep mislabeled files out of the LZH path"],"tags":["archive","lzh","format","validation"],"backgroundTag":"unsupported-archive-format","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}