Artifactspublic-v0

ply

main
ply4 git calls422 ms50 KiB1 cachedprotocol v2
811 lines40 KiBRaw
1// Pull inflate (RFC 1950 + RFC 1951): bytes in as they arrive, output out in chunks of at most INFLATE_CHUNK, a 32 KiB
2// window kept for back-references and nothing else. Peak is the window, one chunk, two 1 KiB code tables and the unread
3// bytes the caller fed; never the inflated object, never the zlib member (issue #172).
4//
5// Codes are looked up INFLATE_FAST_BITS at a time in a table built by puff's own walk (huffFast), from a bit buffer
6// read up to 24 bits ahead; a longer code goes a bit at a time. The bytes read ahead are not consumed: they go back to
7// the input before a byte boundary, at the end and with a full chunk, so the output, `consumed` and every refusal are
8// what a bit-at-a-time decoder gives (test/packstream.test.js holds both to the oracle in every chunking).
9//
10// One owner, one mutable record: an immutable record per symbol would retain every prefix and blow the bound this module
11// exists to hold. A pull runs atomic steps. A step that runs out of input puts back the bits it took (the mark) and the
12// pull answers `need`, so a step never resumes halfway and there is no sentinel to throw. Refusals are values: a step
13// stores its PlyError on the record and the pull returns it (and keeps returning it).
14//
15// The one deflate decoder in ply: inflate() (inflate.ts) is a collector over this pull, so the buffered and the streamed
16// paths give the same answer by construction. On input no git writes, the decoder refuses what zlib and git refuse:
17// - a dynamic block whose code-length, literal/length or distance code set is over-subscribed or incomplete is
18// pack_corrupt with zlib's message (`invalid code lengths set`, `invalid literal/lengths set`, `invalid distances
19// set`), by zlib's own rule (huffComplete); test/inflate-codesets.test.js holds acceptance to node:zlib;
20// - CINFO > 7 is `zlib: window size N is not a zlib window` (after the method check and before the header checksum),
21// and a back-reference that reaches before the first byte of output is `distance too far back`. A smaller CINFO is
22// reported (git.inflate.window) and not enforced, as in stock zlib: inflate.c refuses `len > 15 || len >
23// state->wbits` (15 under git's inflateInit) and reads dmax = 1 << len only under INFLATE_STRICT, which a stock
24// build does not define. So git reads a member whose match reaches past its declared window, and so does ply
25// (test/inflate-zlib-git.test.js: node:zlib and git cat-file on a hand-built loose object);
26// - a stored block whose declared length is past the output cap is refused at its header, before its bytes arrive;
27// - a member cut inside its zlib header is a short read of the bytes fed.
28// The Huffman tables, the alphabets and Adler-32 live here too; inflate.ts re-exports them.
29import type { ErrorOf } from './errors.js';
30import { fail, plyError } from './errors.js';
31import type { Result } from './result.js';
32import { ok, err, assertNever } from './result.js';
33import { shortRead } from './bytes.js';
34import { DEFAULT_LIMITS, checkLimit } from './limits.js';
35import type { Attrs } from './otel.js';
36import {
37 ZLIB_HEADER_BYTES, ZLIB_CM_DEFLATE, ZLIB_CM_MASK, ZLIB_FDICT, ZLIB_HEADER_MOD, ZLIB_CINFO_SHIFT, ZLIB_CINFO_MAX, ZLIB_WINDOW_EXPONENT,
38 ADLER_BYTES, ADLER_MOD, ADLER_NMAX, ADLER_SHIFT, BYTE_SHIFT, BE32_SHIFTS, zlibBound,
39 DEFLATE_BFINAL_BITS, DEFLATE_BTYPE_BITS, DEFLATE_STORED, DEFLATE_FIXED, DEFLATE_DYNAMIC,
40 DEFLATE_STORED_HEADER_BYTES, DEFLATE_STORED_LEN_MASK,
41 DEFLATE_BIT_TABLE, DEFLATE_LITERALS, DEFLATE_EOB, DEFLATE_LENGTH_CODES,
42 DEFLATE_HLIT_BASE, DEFLATE_HLIT_BITS, DEFLATE_HDIST_BASE, DEFLATE_HDIST_BITS, DEFLATE_HCLEN_BASE, DEFLATE_HCLEN_BITS,
43 DEFLATE_HLIT_MAX, DEFLATE_HDIST_MAX, DEFLATE_CODELEN_CODES, DEFLATE_CODELEN_BITS,
44 DEFLATE_REPEAT_PREV, DEFLATE_REPEAT_ZERO3,
45 DEFLATE_REPEAT16_BASE, DEFLATE_REPEAT16_BITS, DEFLATE_REPEAT17_BASE, DEFLATE_REPEAT17_BITS,
46 DEFLATE_REPEAT18_BASE, DEFLATE_REPEAT18_BITS,
47 INFLATE_WINDOW, INFLATE_CHUNK, INFLATE_FAST_BITS, INFLATE_FAST_SYMBOL_BITS, INFLATE_LOOKAHEAD_BITS,
48} from './format.js';
50/* oxlint-disable no-magic-numbers -- RFC 1951 §3.2.5 length/distance alphabets and the fixed Huffman assignment */
51// The length and distance alphabets, built as RFC 1951 §3.2.5 defines them: each code's extra bits, and a base that is
52// the previous base plus the previous code's range (2^extra). Length code 285 is the exception: 0 extra bits, base 258.
53// test/mutant-kill.test.js holds these against the RFC's printed tables.
54const LBASE: number[] = [];
55const LEXT: number[] = [];
56const DBASE: number[] = [];
57const DEXT: number[] = [];
58for (let base = 3, i = 0; i < 29; i++) { const x = i < 8 || i === 28 ? 0 : (i >> 2) - 1; LEXT.push(x); LBASE.push(i === 28 ? 258 : base); base += 1 << x; }
59for (let base = 1, i = 0; i < 30; i++) { const x = i < 4 ? 0 : (i >> 1) - 1; DEXT.push(x); DBASE.push(base); base += 1 << x; }
60export const CLORDER: readonly number[] = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
62export const DEFLATE_TABLES: { readonly LBASE: readonly number[]; readonly LEXT: readonly number[]; readonly DBASE: readonly number[]; readonly DEXT: readonly number[] } = /* @__PURE__ */ Object.freeze({ LBASE, LEXT, DBASE, DEXT });
64export type Huffman = { readonly count: Uint16Array; readonly symbol: Uint16Array };
65// Indexed reads in this file are in range (a length check, a mask, or a table built to the alphabet's size bounds each
66// one), which noUncheckedIndexedAccess cannot see; `as number` says so (src/ forbids the `!` form).
67/* oxlint-disable typescript/no-unsafe-type-assertion, typescript/non-nullable-type-assertion-style -- in-range indexed reads, see above */
68// Canonical Huffman table from code lengths (puff algorithm). Returns {count, symbol}.
69export function huffBuild(lengths: ArrayLike<number>): Huffman {
70 const count = new Uint16Array(DEFLATE_BIT_TABLE);
71 const symbol = new Uint16Array(lengths.length);
72 const offs = new Uint16Array(DEFLATE_BIT_TABLE);
73 // Stryker disable next-line EqualityOperator: one past the end reads past the array (a key a typed array ignores), and count[0] is cleared on the next line
74 for (let i = 0; i < lengths.length; i++) { const l = lengths[i] as number; count[l] = (count[l] as number) + 1; }
75 count[0] = 0;
76 // Stryker disable next-line EqualityOperator: offs is DEFLATE_BIT_TABLE long, so the extra index is ignored
77 for (let l = 1; l < DEFLATE_BIT_TABLE; l++) offs[l] = (offs[l - 1] as number) + (count[l - 1] as number);
78 // Stryker disable next-line EqualityOperator: lengths[lengths.length] is past the end and the if skips it
79 for (let s = 0; s < lengths.length; s++) { const l = lengths[s] as number; if (l) { const at = offs[l] as number; symbol[at] = s; offs[l] = at + 1; } }
80 return { count, symbol };
83// zlib's check of a code set before it builds a table (inftrees.c inflate_table, zlib 1.3.1), which is what git's
84// inflate applies to every dynamic block:
85// left = 1;
86// for (len = 1; len <= MAXBITS; len++) { left <<= 1; left -= count[len]; if (left < 0) return -1; } /* over-subscribed */
87// if (left > 0 && (type == CODES || max != 1)) return -1; /* incomplete set */
88// and, before it, `if (max == 0) { ... return 0; } /* no symbols, but wait for decoding to report error */`.
89// So an over-subscribed set is always refused, and an incomplete one is refused except in the two cases zlib permits:
90// - no code at all (max == 0), in any of the three sets: the table is built and the first symbol decoded from it is
91// the error (here decode finds no code: `invalid huffman code`). A literal/length set never gets here that way (the
92// end-of-block check comes first); a distance set with no codes is what a block of literals alone may carry;
93// - one code of one bit (max == 1), in the literal/length and distance sets only, never in the code-length set
94// (`single` is false for it). The unused 1-bit code is refused when it is read.
95// 15 steps over the count array huffBuild already filled: no allocation, once per table, nothing in the symbol loop.
96export function huffComplete(h: Huffman, single: boolean): boolean {
97 let left = 1;
98 let max = 0;
99 for (let len = 1; len < DEFLATE_BIT_TABLE; len++) {
100 const c = h.count[len] as number;
101 if (c !== 0) max = len;
102 left = (left << 1) - c;
103 if (left < 0) return false;
104 }
105 return left === 0 || max === 0 || (single && max === 1);
108// lengths 0-143: 8, 144-255: 9, 256-279: 7, 280-287: 8
109export const FIXED_LIT: Huffman = huffBuild(new Uint8Array(288).fill(8).fill(9, 144, 256).fill(7, 256, 280));
110export const FIXED_DIST: Huffman = huffBuild(new Uint8Array(30).fill(5));
111/* oxlint-enable no-magic-numbers */
113// A table of every INFLATE_FAST_BITS-bit lookahead, in the order the bits are read (the first bit read is bit 0): the
114// symbol puff's decode gives for it and the length of its code, or 0 where the code is longer or no code matches (the
115// decoder then goes a bit at a time, as before). Built from the same count and symbol arrays and the same walk as
116// decode, so a table lookup and decode agree on every input, an incomplete or over-subscribed code included: at length
117// `len` decode answers the codes first..first+count-1 that fit in len bits, and a code at one length never starts with
118// a shorter one's bits (each length's first code is past the previous length's last, shifted).
119export type FastTable = Uint16Array;
120const FAST_SIZE: number = 1 << INFLATE_FAST_BITS;
121const FAST_MASK: number = FAST_SIZE - 1;
122const FAST_SYMBOL_MASK: number = (1 << INFLATE_FAST_SYMBOL_BITS) - 1;
123// The len low bits of code, reversed: the code's first bit (its highest) is the first bit read.
124function reversed(code: number, len: number): number {
125 let r = 0;
126 for (let i = 0; i < len; i++) r = (r << 1) | ((code >> i) & 1);
127 return r;
129export function huffFast(h: Huffman, into: FastTable = new Uint16Array(FAST_SIZE)): FastTable {
130 into.fill(0);
131 let first = 0;
132 let index = 0;
133 for (let len = 1; len <= INFLATE_FAST_BITS; len++) {
134 const c = h.count[len] as number;
135 // the codes of this length that fit in len bits (an over-subscribed length has more than fit; decode never reads them)
136 const fit = Math.min(c, (1 << len) - first);
137 for (let j = 0; j < fit; j++) {
138 const entry = (len << INFLATE_FAST_SYMBOL_BITS) | (h.symbol[index + j] as number);
139 // every lookahead whose first len bits are this code
140 // Stryker disable next-line EqualityOperator: into[FAST_SIZE] is past the end, which a typed array ignores
141 for (let k = reversed(first + j, len); k < FAST_SIZE; k += 1 << len) into[k] = entry;
142 }
143 index += c;
144 first = (first + c) << 1;
145 }
146 return into;
148const FIXED_LIT_FAST: FastTable = huffFast(FIXED_LIT);
149const FIXED_DIST_FAST: FastTable = huffFast(FIXED_DIST);
151// The sums are reduced every ADLER_NMAX bytes, not every byte: a and b stay exact in a double either way, so the result
152// is the same and the loop does one add pair per byte.
153export function adler32(bytes: Uint8Array, a = 1, b = 0): number {
154 let sa = a;
155 let sb = b;
156 for (let i = 0; i < bytes.length;) {
157 const end = Math.min(i + ADLER_NMAX, bytes.length);
158 for (; i < end; i++) { sa += bytes[i] as number; sb += sa; }
159 sa %= ADLER_MOD;
160 sb %= ADLER_MOD;
161 }
162 return ((sb << ADLER_SHIFT) | sa) >>> 0;
165export type InflateStats = {
166 blocks: number; stored: number; fixed: number; dynamic: number;
167 literals: number; matches: number; matchBytes: number; maxDist: number; maxLen: number;
168};
169export type InflateError = ErrorOf<'pack_corrupt'> | ErrorOf<'limit_exceeded'> | ErrorOf<'bad_request'>;
171const WINDOW_MASK: number = INFLATE_WINDOW - 1;
172const EMPTY: Uint8Array = new Uint8Array(0);
173// The two decode results that are not a symbol. A symbol is a Uint16, so both are below zero.
174const SYM_NEED = -1;
175const SYM_NO_CODE = -2;
177// How the output is bounded: a declared size (a pack header's; the output must be exactly that long) or only a cap.
178export type StreamBound =
179 | { readonly kind: 'declared'; readonly size: number; readonly maxOutput: number }
180 | { readonly kind: 'capped'; readonly maxOutput: number };
181// A zlib member (header and Adler-32 trailer) or a raw deflate stream.
182export type StreamWrap =
183 | { readonly kind: 'zlib'; readonly verifyAdler: boolean }
184 | { readonly kind: 'raw' };
185export type InflateStreamOpts = { readonly bound: StreamBound; readonly wrap: StreamWrap };
187export const zlibWrap = (verifyAdler: boolean): StreamWrap => ({ kind: 'zlib', verifyAdler });
188export const rawWrap = (): StreamWrap => ({ kind: 'raw' });
189export const cappedBound = (maxOutput: number = DEFAULT_LIMITS.maxObjectSize): StreamBound => ({ kind: 'capped', maxOutput });
190export const declaredBound = (size: number, maxOutput: number = DEFAULT_LIMITS.maxObjectSize): StreamBound => ({ kind: 'declared', size, maxOutput });
192export type InflatePhase =
193 | 'header' | 'block' | 'stored-header' | 'stored' | 'dyn-header' | 'dyn-clen' | 'dyn-lens' | 'codes' | 'adler' | 'end';
194// Running, or stopped by a refusal that every later pull returns again.
195export type InflateHalt = { readonly tag: 'running' } | { readonly tag: 'failed'; readonly error: InflateError };
196// Stryker disable next-line ObjectLiteral,StringLiteral: halt is read only as tag === 'failed'; any other record runs
197const RUNNING: InflateHalt = { tag: 'running' };
198// What a pull answers: a chunk of output (a copy the caller owns), a request for more input, or the end of the member
199// with the bytes it consumed. After the end every pull answers the end again.
200export type InflatePiece =
201 | { readonly kind: 'need' }
202 | { readonly kind: 'chunk'; readonly bytes: Uint8Array<ArrayBuffer> }
203 | { readonly kind: 'end'; readonly consumed: number; readonly stats: InflateStats };
205// Single owner. The fields are mutable so a pull can resume; two pulls on one record at once is a bug.
206export type InflateStream = {
207 phase: InflatePhase;
208 halt: InflateHalt;
209 bound: StreamBound;
210 wrap: StreamWrap;
211 maxOutput: number;
212 declared: number;
213 maxInput: number;
214 windowSize: number;
215 ended: boolean;
216 // input: `carry` from `p`, bits not yet used in `bitbuf` (`bitcnt` of them); `base` bytes came before this carry.
217 // The bit buffer may hold whole bytes read ahead (decodeFast). They are not consumed (consumedOf), and they go back to
218 // the carry (settle) before a byte boundary is read (align), at the end (finish), and when a full chunk is answered,
219 // so a feed after a chunk joins the carry behind them. After a need they stay: the step that needed more input
220 // rewound to the start of a symbol whose bits run past them, so the bits are all used before the next boundary.
221 carry: Uint8Array;
222 p: number;
223 base: number;
224 bitbuf: number;
225 bitcnt: number;
226 // the mark a step returns to when it runs out of input
227 markP: number;
228 markBuf: number;
229 markCnt: number;
230 // output: the window ring (`w` is the next write), the chunk being filled, and what the Adler sums have seen of it
231 window: Uint8Array;
232 w: number;
233 out: Uint8Array;
234 outLen: number;
235 summed: number;
236 adler: number;
237 emitted: number;
238 stats: InflateStats;
239 // the block being read
240 final: boolean;
241 storedLeft: number;
242 nlen: number;
243 ndist: number;
244 ncode: number;
245 lensI: number;
246 lengths: Uint8Array;
247 lencode: Huffman;
248 lit: Huffman;
249 dist: Huffman;
250 // the fast tables of lencode (litTab's buffer, before the literal table is built in it), lit and dist: a fixed
251 // block's are shared constants, a dynamic block's are built in this record's two buffers
252 lenFast: FastTable;
253 litFast: FastTable;
254 distFast: FastTable;
255 litTab: FastTable;
256 distTab: FastTable;
257 copyLeft: number;
258 copyDist: number;
259};
261// A step's answer. A refusal is stored on the record first (`refuse`), so the answer itself is a number.
262const CONT = 0;
263const CHUNK = 1;
264const END = 2;
265const NEED = 3;
266const FAILED = 4;
267type Drive = typeof CONT | typeof CHUNK | typeof END | typeof NEED | typeof FAILED;
269function refuse(st: InflateStream, error: InflateError): Drive {
270 st.halt = { tag: 'failed', error };
271 return FAILED;
273// The bytes the decoder has used: a byte read ahead into the bit buffer and not used is not consumed.
274const consumedOf = (st: InflateStream): number => st.base + st.p - Math.floor(st.bitcnt / BYTE_SHIFT);
275// The member bytes used so far, for a caller that weighs output against input (packstream.ts chargeWork).
276export const inflateConsumed: (st: InflateStream) => number = consumedOf;
277const tooLong = (st: InflateStream): ErrorOf<'pack_corrupt'> =>
278 plyError('pack_corrupt', `inflate: zlib stream longer than its declared size allows (${consumedOf(st)} > ${st.maxInput} for ${st.declared} bytes)`);
280function mark(st: InflateStream): void {
281 st.markP = st.p;
282 st.markBuf = st.bitbuf;
283 st.markCnt = st.bitcnt;
285// Put back what the step took, and ask for more input.
286function rewind(st: InflateStream): Drive {
287 st.p = st.markP;
288 st.bitbuf = st.markBuf;
289 st.bitcnt = st.markCnt;
290 return NEED;
292// At least n bits in the bit buffer, or false (input ran out; the bytes pulled so far stay in the buffer).
293function fill(st: InflateStream, n: number): boolean {
294 while (st.bitcnt < n) {
295 if (st.p >= st.carry.length) return false;
296 st.bitbuf |= (st.carry[st.p] as number) << st.bitcnt;
297 st.p += 1;
298 st.bitcnt += BYTE_SHIFT;
299 }
300 return true;
302// n bits the caller has filled.
303function take(st: InflateStream, n: number): number {
304 const v = st.bitbuf & ((1 << n) - 1);
305 st.bitbuf >>>= n;
306 st.bitcnt -= n;
307 return v;
309// puff's decode, one code bit at a time, from the bit buffer decodeFast filled: a symbol, SYM_NEED, or SYM_NO_CODE. That
310// buffer holds every byte there is up to INFLATE_LOOKAHEAD_BITS, more than the longest code, so running out of bits here
311// is running out of input.
312function decode(st: InflateStream, h: Huffman): number {
313 let code = 0;
314 let first = 0;
315 let index = 0;
316 for (let len = 1; len < DEFLATE_BIT_TABLE; len++) {
317 if (st.bitcnt <= 0) return SYM_NEED;
318 code |= st.bitbuf & 1; // oxlint-disable-line oxc/bad-bitwise-operator -- puff's decode: the next bit goes in at bit 0
319 st.bitbuf >>>= 1;
320 st.bitcnt -= 1;
321 const c = h.count[len] as number;
322 if (code - first < c) return h.symbol[index + code - first] as number;
323 index += c;
324 first = (first + c) << 1;
325 code <<= 1;
326 }
327 return SYM_NO_CODE;
329// Whole bytes the bit buffer holds go back to the carry (they were read from it in this pull), and the bits left are
330// fewer than 8: what reading bit by bit would have left. A pull settles before it answers, so a feed after any answer
331// keeps every unused byte.
332function settle(st: InflateStream): void {
333 const whole = Math.floor(st.bitcnt / BYTE_SHIFT);
334 st.p -= whole;
335 st.bitcnt -= whole * BYTE_SHIFT;
336 st.bitbuf &= (1 << st.bitcnt) - 1;
338// A byte boundary (a stored block's header, the Adler-32 trailer): the bytes read ahead go back, the rest of the
339// current byte is padding.
340function align(st: InflateStream): void {
341 settle(st);
342 st.bitbuf = 0;
343 st.bitcnt = 0;
345// decode by the fast table: the bit buffer topped up to INFLATE_LOOKAHEAD_BITS (fewer at the end of the input), its next
346// INFLATE_FAST_BITS bits looked up at once. A code the table does not hold, or one longer than the bits there are, goes
347// to decode, which reads the same bits from the buffer first.
348function decodeFast(st: InflateStream, h: Huffman, table: FastTable): number {
349 const c = st.carry;
350 // Stryker disable next-line EqualityOperator: at 24 bits one more byte still fits 32, and a settle returns it unused
351 while (st.bitcnt < INFLATE_LOOKAHEAD_BITS && st.p < c.length) {
352 st.bitbuf |= (c[st.p] as number) << st.bitcnt;
353 st.p += 1;
354 st.bitcnt += BYTE_SHIFT;
355 }
356 const entry = table[st.bitbuf & FAST_MASK] as number;
357 const len = entry >>> INFLATE_FAST_SYMBOL_BITS;
358 // Stryker disable next-line ConditionalExpression,EqualityOperator: decode reads the same bits to the same symbol (the fast table is a shortcut; test/packstream.test.js holds it to puff's walk)
359 if (entry === 0 || len > st.bitcnt) return decode(st, h);
360 st.bitbuf >>>= len;
361 st.bitcnt -= len;
362 return entry & FAST_SYMBOL_MASK;
364// A decode that did not give a symbol: the input ran out (rewind), or no code matched.
365const undecoded = (st: InflateStream, sym: number): Drive =>
366 (sym === SYM_NEED ? rewind(st) : refuse(st, plyError('pack_corrupt', 'inflate: invalid huffman code')));
368const ROOM: Result<null, never> = ok(null);
369// Room for n more output bytes, as inflate.ts's ensure decides it: past a declared size is pack_corrupt, past the cap
370// limit_exceeded.
371function room(st: InflateStream, n: number): Result<null, InflateError> {
372 const next = st.emitted + n;
373 switch (st.bound.kind) {
374 case 'declared':
375 if (next > st.bound.size) return fail('pack_corrupt', `inflate: output exceeds expected ${st.bound.size}`);
376 return ROOM;
377 case 'capped':
378 if (next > st.maxOutput) return fail('limit_exceeded', `inflate: output exceeds limit ${st.maxOutput}`, { what: 'inflate output', got: next, max: st.maxOutput });
379 return ROOM;
380 }
381 // Stryker disable next-line ConditionalExpression,BlockStatement,CallExpression: unreachable, the compiler's exhaustiveness check
382 return assertNever(st.bound);
384function emit(st: InflateStream, b: number): void {
385 st.window[st.w] = b;
386 st.w = (st.w + 1) & WINDOW_MASK;
387 st.out[st.outLen] = b;
388 st.outLen += 1;
389 st.emitted += 1;
391const full = (st: InflateStream): boolean => st.outLen === INFLATE_CHUNK;
392const ADLER_HALF: number = (1 << ADLER_SHIFT) - 1;
393// The Adler sums over output they have not seen yet. adler32 takes the two sums the packed value holds.
394function sum(st: InflateStream): void {
395 st.adler = adler32(st.out.subarray(st.summed, st.outLen), st.adler & ADLER_HALF, st.adler >>> ADLER_SHIFT);
396 st.summed = st.outLen;
398function takeChunk(st: InflateStream): Uint8Array<ArrayBuffer> {
399 sum(st);
400 const bytes = st.out.slice(0, st.outLen);
401 st.outLen = 0;
402 st.summed = 0;
403 return bytes;
406// ---- steps: each takes all the input it needs or none of it ----
407function declaredFits(bound: StreamBound, maxOutput: number): Result<null, ErrorOf<'limit_exceeded'>> {
408 // Stryker disable next-line ConditionalExpression: a capped bound has no size, and the missing size is not greater than the cap
409 if (bound.kind === 'declared' && bound.size > maxOutput) return fail('limit_exceeded', `inflate: expected size ${bound.size} exceeds limit ${maxOutput}`, { what: 'inflate expected size', got: bound.size, max: maxOutput });
410 return ROOM;
412function stepHeader(st: InflateStream): Drive {
413 // nothing is consumed before the header is whole, so the carry starts at it (p is 0)
414 if (st.carry.length < ZLIB_HEADER_BYTES) return NEED;
415 const cmf = st.carry[st.p] as number;
416 const flg = st.carry[st.p + 1] as number;
417 const method = cmf & ZLIB_CM_MASK;
418 if (method !== ZLIB_CM_DEFLATE) return refuse(st, plyError('pack_corrupt', `zlib: unsupported method ${method}`));
419 const cinfo = cmf >> ZLIB_CINFO_SHIFT;
420 if (cinfo > ZLIB_CINFO_MAX) return refuse(st, plyError('pack_corrupt', `zlib: window size ${cinfo} is not a zlib window`));
421 if (((cmf << BYTE_SHIFT) | flg) % ZLIB_HEADER_MOD !== 0) return refuse(st, plyError('pack_corrupt', 'zlib: bad header check'));
422 if ((flg & ZLIB_FDICT) !== 0) return refuse(st, plyError('pack_corrupt', 'zlib: preset dictionary not supported'));
423 st.p += ZLIB_HEADER_BYTES;
424 st.windowSize = 1 << (cinfo + ZLIB_WINDOW_EXPONENT);
425 // inflate.ts refuses a declared size past the cap after the header, so a bad header is reported first here too
426 const declared = declaredFits(st.bound, st.maxOutput);
427 if (!declared.ok) return refuse(st, declared.error);
428 st.phase = 'block';
429 return CONT;
431function finish(st: InflateStream): Drive {
432 // a raw stream ends inside its last byte: the bytes read past it are what follows the stream
433 settle(st);
434 if (st.bound.kind === 'declared' && st.emitted !== st.bound.size) return refuse(st, plyError('pack_corrupt', `inflate: size ${st.emitted} != expected ${st.bound.size}`));
435 if (consumedOf(st) > st.maxInput) return refuse(st, tooLong(st));
436 st.phase = 'end';
437 return CONT;
439function endBlock(st: InflateStream): Drive {
440 if (!st.final) {
441 st.phase = 'block';
442 return CONT;
443 }
444 switch (st.wrap.kind) {
445 case 'zlib':
446 // the trailer is byte-aligned: the rest of the last byte is padding
447 align(st);
448 st.phase = 'adler';
449 return CONT;
450 case 'raw':
451 return finish(st);
452 }
453 // Stryker disable next-line ConditionalExpression,BlockStatement,CallExpression: unreachable, the compiler's exhaustiveness check
454 return assertNever(st.wrap);
456function stepBlock(st: InflateStream): Drive {
457 // where a block starts, as inflate.ts checks it: an endless run of empty blocks is refused a few bytes past the bound
458 if (consumedOf(st) > st.maxInput) return refuse(st, tooLong(st));
459 if (!fill(st, DEFLATE_BFINAL_BITS + DEFLATE_BTYPE_BITS)) return NEED;
460 st.final = take(st, DEFLATE_BFINAL_BITS) === 1;
461 const btype = take(st, DEFLATE_BTYPE_BITS);
462 st.stats.blocks += 1;
463 switch (btype) {
464 case DEFLATE_STORED:
465 st.stats.stored += 1;
466 // a stored block starts on a byte boundary: the rest of this byte is discarded
467 align(st);
468 st.phase = 'stored-header';
469 return CONT;
470 case DEFLATE_FIXED:
471 st.stats.fixed += 1;
472 st.lit = FIXED_LIT;
473 st.dist = FIXED_DIST;
474 st.litFast = FIXED_LIT_FAST;
475 st.distFast = FIXED_DIST_FAST;
476 st.phase = 'codes';
477 return CONT;
478 case DEFLATE_DYNAMIC:
479 st.stats.dynamic += 1;
480 st.phase = 'dyn-header';
481 return CONT;
482 default:
483 return refuse(st, plyError('pack_corrupt', 'inflate: invalid block type'));
484 }
486function stepStoredHeader(st: InflateStream): Drive {
487 if (st.carry.length - st.p < DEFLATE_STORED_HEADER_BYTES) return NEED;
488 const c = st.carry;
489 const at = st.p;
490 const len = (c[at] as number) | ((c[at + 1] as number) << BYTE_SHIFT);
491 // LEN, then NLEN, each two bytes little-endian (RFC 1951 §3.2.4)
492 // oxlint-disable-next-line no-magic-numbers -- NLEN's first byte is the header's third
493 const nlen = (c[at + 2] as number) | ((c[at + DEFLATE_STORED_HEADER_BYTES - 1] as number) << BYTE_SHIFT);
494 if (len !== (~nlen & DEFLATE_STORED_LEN_MASK)) return refuse(st, plyError('pack_corrupt', 'inflate: stored length check failed'));
495 const fits = room(st, len);
496 if (!fits.ok) return refuse(st, fits.error);
497 st.p += DEFLATE_STORED_HEADER_BYTES;
498 st.storedLeft = len;
499 st.phase = 'stored';
500 return CONT;
502// Copy what is here of the stored block, up to the end of the chunk.
503function stepStored(st: InflateStream): Drive {
504 if (st.storedLeft === 0) return endBlock(st);
505 const n = Math.min(st.storedLeft, st.carry.length - st.p, INFLATE_CHUNK - st.outLen);
506 if (n === 0) return full(st) ? CHUNK : NEED;
507 const src = st.carry.subarray(st.p, st.p + n);
508 st.out.set(src, st.outLen);
509 // the window takes the same bytes, in at most two pieces around its end
510 const head = Math.min(n, INFLATE_WINDOW - st.w);
511 st.window.set(src.subarray(0, head), st.w);
512 st.window.set(src.subarray(head), 0);
513 st.w = (st.w + n) & WINDOW_MASK;
514 st.outLen += n;
515 st.emitted += n;
516 st.p += n;
517 st.storedLeft -= n;
518 return full(st) ? CHUNK : CONT;
520function stepDynHeader(st: InflateStream): Drive {
521 if (!fill(st, DEFLATE_HLIT_BITS + DEFLATE_HDIST_BITS + DEFLATE_HCLEN_BITS)) return NEED;
522 st.nlen = take(st, DEFLATE_HLIT_BITS) + DEFLATE_HLIT_BASE;
523 st.ndist = take(st, DEFLATE_HDIST_BITS) + DEFLATE_HDIST_BASE;
524 st.ncode = take(st, DEFLATE_HCLEN_BITS) + DEFLATE_HCLEN_BASE;
525 if (st.nlen > DEFLATE_HLIT_MAX || st.ndist > DEFLATE_HDIST_MAX) return refuse(st, plyError('pack_corrupt', 'inflate: bad dynamic counts'));
526 st.lengths.fill(0);
527 st.lensI = 0;
528 st.phase = 'dyn-clen';
529 return CONT;
531function stepDynClen(st: InflateStream): Drive {
532 while (st.lensI < st.ncode) {
533 if (!fill(st, DEFLATE_CODELEN_BITS)) return NEED;
534 st.lengths[CLORDER[st.lensI] as number] = take(st, DEFLATE_CODELEN_BITS);
535 st.lensI += 1;
536 }
537 st.lencode = huffBuild(st.lengths.subarray(0, DEFLATE_CODELEN_CODES));
538 if (!huffComplete(st.lencode, false)) return refuse(st, plyError('pack_corrupt', 'inflate: invalid code lengths set'));
539 st.lenFast = huffFast(st.lencode, st.litTab);
540 st.lensI = 0;
541 st.phase = 'dyn-lens';
542 return CONT;
544// One code length symbol and its repeat bits, or none of them.
545function stepDynLens(st: InflateStream): Drive {
546 const total = st.nlen + st.ndist;
547 if (st.lensI >= total) {
548 if (st.lengths[DEFLATE_EOB] === 0) return refuse(st, plyError('pack_corrupt', 'inflate: no end-of-block code'));
549 // zlib's order (inflate.c CODELENS): the end-of-block check, the literal/length set, then the distance set
550 st.lit = huffBuild(Array.from(st.lengths.subarray(0, st.nlen)));
551 if (!huffComplete(st.lit, true)) return refuse(st, plyError('pack_corrupt', 'inflate: invalid literal/lengths set'));
552 st.dist = huffBuild(Array.from(st.lengths.subarray(st.nlen, total)));
553 if (!huffComplete(st.dist, true)) return refuse(st, plyError('pack_corrupt', 'inflate: invalid distances set'));
554 st.litFast = huffFast(st.lit, st.litTab);
555 st.distFast = huffFast(st.dist, st.distTab);
556 st.phase = 'codes';
557 return CONT;
558 }
559 mark(st);
560 const sym = decodeFast(st, st.lencode, st.lenFast);
561 if (sym < 0) return undecoded(st, sym);
562 if (sym < DEFLATE_REPEAT_PREV) {
563 st.lengths[st.lensI] = sym;
564 st.lensI += 1;
565 return CONT;
566 }
567 if (sym === DEFLATE_REPEAT_PREV && st.lensI === 0) return refuse(st, plyError('pack_corrupt', 'inflate: repeat with no previous'));
568 let base = DEFLATE_REPEAT18_BASE;
569 let bits = DEFLATE_REPEAT18_BITS;
570 let val = 0;
571 if (sym === DEFLATE_REPEAT_PREV) {
572 val = st.lengths[st.lensI - 1] as number;
573 base = DEFLATE_REPEAT16_BASE;
574 bits = DEFLATE_REPEAT16_BITS;
575 } else if (sym === DEFLATE_REPEAT_ZERO3) {
576 base = DEFLATE_REPEAT17_BASE;
577 bits = DEFLATE_REPEAT17_BITS;
578 }
579 if (!fill(st, bits)) return rewind(st);
580 const rep = base + take(st, bits);
581 if (st.lensI + rep > total) return refuse(st, plyError('pack_corrupt', 'inflate: repeat overflow'));
582 st.lengths.fill(val, st.lensI, st.lensI + rep);
583 st.lensI += rep;
584 return CONT;
586// The pending match's bytes that fit in the chunk, through the window (a match may overlap its own output: the bytes it
587// reads are the ones it has just written).
588function copyMatch(st: InflateStream): void {
589 const n = Math.min(st.copyLeft, INFLATE_CHUNK - st.outLen);
590 const win = st.window;
591 const out = st.out;
592 let w = st.w;
593 let from = (w - st.copyDist) & WINDOW_MASK;
594 let o = st.outLen;
595 for (let i = 0; i < n; i++) {
596 const b = win[from] as number;
597 win[w] = b;
598 out[o] = b;
599 o += 1;
600 w = (w + 1) & WINDOW_MASK;
601 from = (from + 1) & WINDOW_MASK;
602 }
603 st.w = w;
604 st.outLen = o;
605 st.emitted += n;
606 st.copyLeft -= n;
608// Symbols until the chunk is full, the block ends, the input runs out or a refusal: each time round the pending match
609// first, then one literal, end of block, or length/distance pair (all of its bits or none).
610function stepCodes(st: InflateStream): Drive {
611 for (;;) {
612 copyMatch(st);
613 // a literal needs one byte of chunk, a match's copy at least one: a full chunk goes out before the next symbol
614 if (full(st)) return CHUNK;
615 mark(st);
616 const sym = decodeFast(st, st.lit, st.litFast);
617 if (sym < 0) return undecoded(st, sym);
618 if (sym < DEFLATE_LITERALS) {
619 const fits = room(st, 1);
620 if (!fits.ok) return refuse(st, fits.error);
621 emit(st, sym);
622 st.stats.literals += 1;
623 continue;
624 }
625 if (sym === DEFLATE_EOB) return endBlock(st);
626 const li = sym - DEFLATE_HLIT_BASE;
627 if (li >= DEFLATE_LENGTH_CODES) return refuse(st, plyError('pack_corrupt', 'inflate: bad length symbol'));
628 const lbits = LEXT[li] as number;
629 // Stryker disable next-line ConditionalExpression: short extra bits mean the input is spent, so the distance decode below finds no bits (decode answers need) and rewinds to the same mark
630 if (!fill(st, lbits)) return rewind(st);
631 const len = (LBASE[li] as number) + take(st, lbits);
632 const di = decodeFast(st, st.dist, st.distFast);
633 if (di < 0) return undecoded(st, di);
634 // a distance table is built from at most DEFLATE_HDIST_MAX lengths (FIXED_DIST from 30), so di indexes DBASE and DEXT
635 const dbits = DEXT[di] as number;
636 if (!fill(st, dbits)) return rewind(st);
637 const d = (DBASE[di] as number) + take(st, dbits);
638 // zlib's rule (inflate.c: offset > whave + out - left): only the output produced bounds a distance. The largest
639 // distance deflate spells is the ring's size, so the read stays inside the ring.
640 if (d > st.emitted) return refuse(st, plyError('pack_corrupt', 'inflate: distance too far back'));
641 const fits = room(st, len);
642 if (!fits.ok) return refuse(st, fits.error);
643 st.stats.matches += 1;
644 st.stats.matchBytes += len;
645 // Stryker disable next-line EqualityOperator: writing the same maximum when the distance is equal does not change the stat
646 if (d > st.stats.maxDist) st.stats.maxDist = d;
647 // Stryker disable next-line EqualityOperator: writing the same maximum when the length is equal does not change the stat
648 if (len > st.stats.maxLen) st.stats.maxLen = len;
649 st.copyLeft = len;
650 st.copyDist = d;
651 }
653function stepAdler(st: InflateStream): Drive {
654 if (st.carry.length - st.p < ADLER_BYTES) return NEED;
655 const c = st.carry;
656 const at = st.p;
657 // oxlint-disable-next-line no-magic-numbers -- at + 2 is the third byte of the four BE32_SHIFTS places
658 const want = (((c[at] as number) << (BE32_SHIFTS[0] as number)) | ((c[at + 1] as number) << (BE32_SHIFTS[1] as number)) | ((c[at + 2] as number) << (BE32_SHIFTS[2] as number)) | (c[at + ADLER_BYTES - 1] as number)) >>> 0;
659 sum(st);
660 // a raw stream never reaches this phase (endBlock)
661 // Stryker disable next-line ConditionalExpression: a raw stream never reaches this phase, so its kind is always zlib here
662 if (st.wrap.kind === 'zlib' && st.wrap.verifyAdler && st.adler !== want) return refuse(st, plyError('pack_corrupt', 'inflate: adler32 mismatch'));
663 st.p += ADLER_BYTES;
664 return finish(st);
667function dispatch(st: InflateStream): Drive {
668 switch (st.phase) {
669 case 'header': return stepHeader(st);
670 case 'block': return stepBlock(st);
671 case 'stored-header': return stepStoredHeader(st);
672 case 'stored': return stepStored(st);
673 case 'dyn-header': return stepDynHeader(st);
674 case 'dyn-clen': return stepDynClen(st);
675 case 'dyn-lens': return stepDynLens(st);
676 case 'codes': return stepCodes(st);
677 case 'adler': return stepAdler(st);
678 case 'end': return st.outLen > 0 ? CHUNK : END;
679 }
680 // Stryker disable next-line ConditionalExpression,BlockStatement,CallExpression: unreachable, the compiler's exhaustiveness check
681 return assertNever(st.phase);
684// Input closed inside the member: which truncation it is, by where it stopped (inflate.ts's messages).
685function truncated(st: InflateStream): ErrorOf<'pack_corrupt'> {
686 switch (st.phase) {
687 // nothing is consumed before the header is whole: every byte fed is unread
688 case 'header': return shortRead('pack_corrupt', 0, ZLIB_HEADER_BYTES, st.carry.length);
689 case 'stored-header': return plyError('pack_corrupt', 'inflate: truncated stored header');
690 case 'stored': return plyError('pack_corrupt', 'inflate: truncated stored block');
691 case 'adler': return plyError('pack_corrupt', 'inflate: truncated adler32');
692 // Stryker disable next-line ConditionalExpression,StringLiteral: an ended member never asks for input, so 'end' is never truncated
693 case 'end':
694 case 'block': case 'dyn-header': case 'dyn-clen': case 'dyn-lens': case 'codes':
695 return plyError('pack_corrupt', 'inflate: unexpected end of input');
696 }
697 // Stryker disable next-line ConditionalExpression,BlockStatement,CallExpression: unreachable, the compiler's exhaustiveness check
698 return assertNever(st.phase);
701const NEED_PIECE: InflatePiece = { kind: 'need' };
702// The next piece: a chunk when one is full (or the input ran out with output pending), the end, or a request for input.
703// A refusal (FAILED) is on the record: the loop goes round once more and returns it.
704export function inflatePull(st: InflateStream): Result<InflatePiece, InflateError> {
705 for (;;) {
706 if (st.halt.tag === 'failed') return err(st.halt.error);
707 const d = dispatch(st);
708 // a full chunk leaves the carry holding the bytes not used: the caller may feed before the next need (see
709 // InflateStream); the end has settled (finish)
710 if (d === CHUNK) {
711 settle(st);
712 return ok({ kind: 'chunk', bytes: takeChunk(st) });
713 }
714 if (d === END) return ok({ kind: 'end', consumed: consumedOf(st), stats: { ...st.stats } });
715 if (d === NEED) {
716 if (st.outLen > 0) return ok({ kind: 'chunk', bytes: takeChunk(st) });
717 if (!st.ended) return ok(NEED_PIECE);
718 refuse(st, truncated(st));
719 }
720 }
722// No more input will come: the pull from here on finishes the member or reports where it was cut.
723export function inflateEnd(st: InflateStream): Result<InflatePiece, InflateError> {
724 st.ended = true;
725 return inflatePull(st);
728// Append input. An exhausted carry is replaced by `bytes` itself (no copy); a leftover tail (at most the few bytes one
729// step needs) is copied in front of it once, so the caller may drop what it fed before.
730export function inflateFeed(st: InflateStream, bytes: Uint8Array): void {
731 if (st.p >= st.carry.length) {
732 st.base += st.p;
733 st.carry = bytes;
734 st.p = 0;
735 return;
736 }
737 const tail = st.carry.subarray(st.p);
738 const joined = new Uint8Array(tail.length + bytes.length);
739 joined.set(tail, 0);
740 joined.set(bytes, tail.length);
741 st.base += st.p;
742 st.carry = joined;
743 st.p = 0;
745// Bytes fed and not consumed: after the end, what follows the member. A view, valid until the next feed or reset.
746export function inflateUnread(st: InflateStream): Uint8Array {
747 return st.carry.subarray(st.p);
750const freshStats = (): InflateStats => ({ blocks: 0, stored: 0, fixed: 0, dynamic: 0, literals: 0, matches: 0, matchBytes: 0, maxDist: 0, maxLen: 0 });
751// The record's buffers. inflateReset sets every other field a member reads before its first pull (blank's values are
752// placeholders, so Stryker's changes to them are equivalent).
753function blank(): InflateStream {
754 return {
755 // Stryker disable next-line all: placeholders, see above
756 phase: 'header', halt: RUNNING, bound: cappedBound(), wrap: rawWrap(), maxOutput: 0, declared: 0, maxInput: 0,
757 // Stryker disable next-line all: placeholders, see above
758 windowSize: INFLATE_WINDOW, ended: false, carry: EMPTY, p: 0, base: 0, bitbuf: 0, bitcnt: 0, markP: 0, markBuf: 0, markCnt: 0,
759 window: new Uint8Array(INFLATE_WINDOW), w: 0, out: new Uint8Array(INFLATE_CHUNK), outLen: 0, summed: 0, adler: 1, emitted: 0,
760 // Stryker disable next-line all: placeholders, see above (a block header sets `final` and the counts before they are read)
761 stats: freshStats(), final: false, storedLeft: 0, nlen: 0, ndist: 0, ncode: 0, lensI: 0,
762 lengths: new Uint8Array(DEFLATE_HLIT_MAX + DEFLATE_HDIST_MAX), lencode: FIXED_LIT, lit: FIXED_LIT, dist: FIXED_DIST,
763 // Stryker disable next-line all: placeholders, see above (a block header sets the tables before they are read)
764 lenFast: FIXED_LIT_FAST, litFast: FIXED_LIT_FAST, distFast: FIXED_DIST_FAST,
765 litTab: new Uint16Array(FAST_SIZE), distTab: new Uint16Array(FAST_SIZE), copyLeft: 0, copyDist: 0,
766 };
768// Start a member on an existing record: the window and chunk buffers are kept (a pack scan inflates one member per
769// object), everything else starts over. The old carry is dropped.
770export function inflateReset(st: InflateStream, opts: InflateStreamOpts): Result<InflateStream, InflateError> {
771 const max = checkLimit(opts.bound.maxOutput, 'maxObjectSize');
772 if (!max.ok) return max;
773 // a raw stream has no header to report first (inflate.ts checks this before reading a block)
774 if (opts.wrap.kind === 'raw') {
775 const declared = declaredFits(opts.bound, max.value);
776 if (!declared.ok) return declared;
777 }
778 const declared = opts.bound.kind === 'declared' ? opts.bound.size : max.value;
779 st.phase = opts.wrap.kind === 'raw' ? 'block' : 'header';
780 st.halt = RUNNING;
781 st.bound = opts.bound;
782 st.wrap = opts.wrap;
783 st.maxOutput = max.value;
784 st.declared = declared;
785 st.maxInput = zlibBound(declared);
786 st.windowSize = INFLATE_WINDOW;
787 st.ended = false;
788 st.carry = EMPTY;
789 st.p = 0;
790 st.base = 0;
791 st.bitbuf = 0;
792 st.bitcnt = 0;
793 st.w = 0;
794 st.outLen = 0;
795 st.summed = 0;
796 st.adler = 1;
797 st.emitted = 0;
798 st.stats = freshStats();
799 st.storedLeft = 0;
800 st.copyLeft = 0;
801 st.copyDist = 0;
802 return ok(st);
804export function inflateInit(opts: InflateStreamOpts): Result<InflateStream, InflateError> {
805 return inflateReset(blank(), opts);
808export const streamInflateAttrs = (st: InflateStream): Attrs => ({
809 'git.inflate.phase': st.phase, 'git.inflate.consumed': consumedOf(st), 'git.inflate.emitted': st.emitted,
810 'git.inflate.window': st.windowSize, 'git.inflate.ended': st.ended,
811});
Diagnostics4 git calls · 422 ms
CallStatusSizeTime0422 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=UPDATING
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch20012 KiB416 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=416
git.response.bytes=12576
git.response.cache=MISS
git.response.duration_ms=416
git.fetch.wants=154e090b4b288f5ac3904256c79d7531cd32c001
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=12576
git.pkt.payload.max=12555
git.sideband.band1.bytes=12554
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e296162be32407
Request
a6fb7f7b…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format