( buf: Uint8Array, pos: number, limits: Pick<ParsePackLimits, "maxObjectBytes"> = DEFAULT_LIMITS, )
| 276 | |
| 277 | // zlib wrapper: 2-byte header, deflate, 4-byte adler32. Return inflated + end offset. |
| 278 | function inflateZlib( |
| 279 | buf: Uint8Array, |
| 280 | pos: number, |
| 281 | limits: Pick<ParsePackLimits, "maxObjectBytes"> = DEFAULT_LIMITS, |
| 282 | ): { out: Uint8Array; endPos: number } { |
| 283 | requireAvailable(buf, pos, 2, "zlib header"); |
| 284 | const cmf = buf[pos]!; |
| 285 | const flg = buf[pos + 1]!; |
| 286 | if ((cmf & 0x0f) !== 8) throw new PackParseError("unsupported zlib compression method"); |
| 287 | if ((cmf * 256 + flg) % 31 !== 0) throw new PackParseError("bad zlib header checksum"); |
| 288 | if ((flg & 0x20) !== 0) throw new PackParseError("zlib preset dictionaries are not supported"); |
| 289 | const r = inflateRaw(buf, pos + 2, limits); |
| 290 | requireAvailable(buf, r.endPos, 4, "zlib adler32 trailer"); |
| 291 | const expected = new DataView(buf.buffer, buf.byteOffset + r.endPos, 4).getUint32(0); |
| 292 | const actual = adler32(r.out); |
| 293 | if (expected !== actual) throw new PackParseError("bad zlib adler32"); |
| 294 | return { out: r.out, endPos: r.endPos + 4 }; |
| 295 | } |
| 296 | |
| 297 | // --- Packfile top-level parse --- |
| 298 | interface RawObj { |
no test coverage detected