GitHubivarvong

ply

main
ply7 git calls393 ms26 KiB5 cachedprotocol v2
83 lines7.8 KiBRaw
1// Pure byte-level mutations of server responses. Each takes (rng, bytes) → bytes and names what it did.
2// Protocol-aware ones locate pkt-line length fields, sideband band bytes and pack object headers so the
3// fuzzer reaches parser branches that random bit flips rarely hit.
4import { concat } from '../../src/bytes.js';
5import { encodeObjHeader } from '../../src/pack.js';
7const te = new TextEncoder();
8const splice = (b, at, del, ins = new Uint8Array(0)) => concat([b.subarray(0, at), ins, b.subarray(at + del)]);
10export const MUTATORS = {
11 flip_bit: (rng, b) => { if (!b.length) return b; const o = b.slice(); const i = rng.int(0, b.length - 1); o[i] ^= 1 << rng.int(0, 7); return o; },
12 flip_byte: (rng, b) => { if (!b.length) return b; const o = b.slice(); o[rng.int(0, b.length - 1)] = rng.u32() & 0xff; return o; },
13 zero_run: (rng, b) => { if (!b.length) return b; const o = b.slice(); const i = rng.int(0, b.length - 1); o.fill(0, i, Math.min(b.length, i + rng.int(1, 64))); return o; },
14 truncate: (rng, b) => b.subarray(0, rng.int(0, Math.max(0, b.length - 1))),
15 truncate_tail: (rng, b) => b.subarray(0, Math.max(0, b.length - rng.int(1, 24))),
16 delete_run: (rng, b) => { if (b.length < 2) return b; const i = rng.int(0, b.length - 2); return splice(b, i, rng.int(1, Math.min(64, b.length - i))); },
17 insert_junk: (rng, b) => splice(b, rng.int(0, b.length), 0, rng.bytes(rng.int(1, 64))),
18 duplicate_run: (rng, b) => { if (b.length < 2) return b; const i = rng.int(0, b.length - 2), n = rng.int(1, Math.min(200, b.length - i)); return splice(b, i, 0, b.subarray(i, i + n)); },
19 append_junk: (rng, b) => concat([b, rng.bytes(rng.int(1, 100))]),
20 append_flush: (rng, b) => concat([b, te.encode('0000')]),
21 empty: () => new Uint8Array(0),
22 swap_runs: (rng, b) => { if (b.length < 40) return b; const n = rng.int(1, Math.min(16, b.length >> 2)); const i = rng.int(0, b.length - 2 * n - 1), j = rng.int(i + n, b.length - n); const o = b.slice(); o.set(b.subarray(j, j + n), i); o.set(b.subarray(i, i + n), j); return o; },
24 // ---- pkt-line aware ----
25 pkt_len: (rng, b) => { const offs = pktOffsets(b); if (!offs.length) return b; const o = b.slice(); const at = rng.pick(offs); const v = rng.pick(['0000', '0001', '0002', '0003', 'ffff', 'zzzz', '0004', '0005', (rng.int(4, 70000)).toString(16).padStart(4, '0').slice(-4)]); o.set(te.encode(v), at); return o; },
26 pkt_drop: (rng, b) => { const offs = pktOffsets(b); if (offs.length < 2) return b; const k = rng.int(0, offs.length - 1); const end = k + 1 < offs.length ? offs[k + 1] : b.length; return splice(b, offs[k], end - offs[k]); },
27 pkt_dup: (rng, b) => { const offs = pktOffsets(b); if (!offs.length) return b; const k = rng.int(0, offs.length - 1); const end = k + 1 < offs.length ? offs[k + 1] : b.length; return splice(b, offs[k], 0, b.subarray(offs[k], end)); },
28 pkt_inject_band2: (rng, b) => { const offs = pktOffsets(b); if (!offs.length) return b; const msg = concat([Uint8Array.of(2), te.encode(`remote: ${'x'.repeat(rng.int(0, 300))}\r`)]); return splice(b, rng.pick(offs), 0, pkt(msg)); },
29 pkt_inject_band3: (rng, b) => { const offs = pktOffsets(b); if (!offs.length) return b; return splice(b, rng.pick(offs), 0, pkt(concat([Uint8Array.of(3), te.encode('fatal: injected')]))); },
30 pkt_inject_err: (rng, b) => { const offs = pktOffsets(b); if (!offs.length) return b; return splice(b, rng.pick(offs), 0, pkt(te.encode('ERR injected\n'))); },
31 band_swap: (rng, b) => { const offs = pktOffsets(b).filter(o => b.length > o + 4 && (b[o + 4] === 1 || b[o + 4] === 2)); if (!offs.length) return b; const o = b.slice(); o[rng.pick(offs) + 4] = rng.pick([0, 1, 2, 3, 4, 255]); return o; },
32 pkt_shallow_flood: (rng, b) => { const offs = pktOffsets(b); if (!offs.length) return b; const n = rng.int(1000, 1500); const lines = []; for (let i = 0; i < n; i++) lines.push(pkt(te.encode(`shallow ${'a'.repeat(40)}\n`))); return splice(b, offs[0], 0, concat([pkt(te.encode('shallow-info\n')), ...lines, te.encode('0001')])); },
34 // ---- pack aware (operates inside band-1 payload of the first pack frame) ----
35 pack_count: (rng, b) => inPack(b, (p) => { const o = p.slice(); new DataView(o.buffer, o.byteOffset).setUint32(8, rng.pick([0, 2, 7, 0xffffffff, 1000000])); return o; }),
36 pack_version: (rng, b) => inPack(b, (p) => { const o = p.slice(); new DataView(o.buffer, o.byteOffset).setUint32(4, rng.pick([0, 1, 3, 0xffffffff])); return o; }),
37 pack_objtype: (rng, b) => inPack(b, (p) => { const o = p.slice(); o[12] = (o[12] & 0x8f) | (rng.pick([0, 1, 2, 4, 5, 6, 7]) << 4); return o; }),
38 pack_objsize: (rng, b) => inPack(b, (p) => { const o = p.slice(); o[12] = (o[12] & 0x70) | 0x80 | rng.int(0, 15); return splice(o, 13, 0, Uint8Array.from(rng.pick([[0x7f], [0xff, 0xff, 0xff, 0xff, 0x0f], [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f], [0x80, 0x80, 0x80, 0x01]]))); }),
39 pack_sig: (rng, b) => inPack(b, (p) => { const o = p.slice(); o[rng.int(0, 3)] ^= 0x20; return o; }),
40 pack_trailer: (rng, b) => inPack(b, (p) => { const o = p.slice(); if (o.length >= 20) o[o.length - 1 - rng.int(0, 19)] ^= 0xff; return o; }),
41 zlib_header: (rng, b) => inPack(b, (p) => { const o = p.slice(); if (o.length > 14) { o[13] = rng.pick([0x00, 0x78, 0x79, 0xff]); o[14] = rng.pick([0x9c, 0x01, 0xda, 0x00, 0x20]); } return o; }),
42 zlib_body: (rng, b) => inPack(b, (p) => { const o = p.slice(); if (o.length > 36) o[rng.int(15, o.length - 21)] ^= 1 << rng.int(0, 7); return o; }),
43 zlib_bomb: (rng, b) => inPack(b, () => { // 1 object claiming 1 MiB of zeros, honest zlib (so adler passes) but declared size differs from header
44 const hdr = new Uint8Array(12); hdr.set([0x50, 0x41, 0x43, 0x4b]); new DataView(hdr.buffer).setUint32(4, 2); new DataView(hdr.buffer).setUint32(8, 1);
45 return concat([hdr, Uint8Array.from([0x30 | 0x80 | 0x0f, 0xff, 0x3f]), ZEROS_1M]); }),
46 zlib_endless_stored: (rng, b) => inPack(b, () => { // a valid blob header, then non-final empty stored blocks (5 bytes in, 0 bytes out), usually far past zlibBound(size)
47 const hdr = new Uint8Array(12); hdr.set([0x50, 0x41, 0x43, 0x4b]); new DataView(hdr.buffer).setUint32(4, 2); new DataView(hdr.buffer).setUint32(8, 1);
48 const size = rng.pick([0, 10, 1000, 70000]);
49 const n = rng.pick([1, 4, 100, rng.int(1000, 60000)]);
50 const blocks = new Uint8Array(5 * n); for (let i = 0; i < blocks.length; i += 5) blocks.set([0, 0, 0, 0xff, 0xff], i);
51 return concat([hdr, encodeObjHeader(3, size), Uint8Array.of(0x78, 0x01), blocks, new Uint8Array(rng.bool() ? 20 : 0)]); }),
52};
53export const MUTATOR_NAMES = Object.keys(MUTATORS);
55export function pktOffsets(b) {
56 const offs = []; let p = 0;
57 while (p + 4 <= b.length) {
58 const len = parseInt(String.fromCharCode(b[p], b[p + 1], b[p + 2], b[p + 3]), 16);
59 if (!Number.isFinite(len)) break;
60 offs.push(p);
61 p += len < 4 ? 4 : len;
62 }
63 return offs;
65const pkt = payload => concat([te.encode((payload.length + 4).toString(16).padStart(4, '0')), payload]);
67// Find first band-1 frame starting with PACK; apply f to the concatenation of ALL band-1 payloads, then re-frame.
68function inPack(b, f) {
69 const offs = pktOffsets(b);
70 const frames = offs.map((o, i) => ({ o, end: i + 1 < offs.length ? offs[i + 1] : b.length }));
71 const band1 = frames.filter(fr => fr.end - fr.o > 5 && b[fr.o + 4] === 1);
72 if (!band1.length) return b;
73 const payload = concat(band1.map(fr => b.subarray(fr.o + 5, fr.end)));
74 if (payload.length < 40 || payload[0] !== 0x50) return b;
75 const mutated = f(payload);
76 const pre = b.subarray(0, band1[0].o), post = b.subarray(band1[band1.length - 1].end);
77 const out = [pre];
78 for (let i = 0; i < mutated.length; i += 65000) out.push(pkt(concat([Uint8Array.of(1), mutated.subarray(i, Math.min(i + 65000, mutated.length))])));
79 out.push(post);
80 return concat(out);
82let ZEROS_1M;
83try { const z = await import('node:zlib'); ZEROS_1M = new Uint8Array(z.deflateSync(Buffer.alloc(1 << 20))); } catch { ZEROS_1M = new Uint8Array(0); }
Diagnostics7 git calls · 393 ms
CallStatusSizeTime0393 ms
discover200191 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=191
git.server.agent=git/github-9922ec520325-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=191
git.pkt.payload.max=36
ls-refs20012 KiB · hit4 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=11990
git.response.cache=HIT
git.response.duration_ms=4
git.protocol.version=2
git.pkt.frames=152
git.pkt.data=151
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=11990
git.pkt.payload.max=122
git.ls_refs.count=151
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit2 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=4347
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
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=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4347
git.pkt.payload.max=4247
git.sideband.band1.bytes=4247
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=4247
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400
git.pack.full=10
Open pack map
fetchtree:0200919 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=919
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=919
git.pkt.payload.max=892
git.sideband.band1.bytes=892
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=892
git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76e
Open pack map
fetchtree:02005.6 KiB · hit2 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=5724
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=5724
git.pkt.payload.max=5697
git.sideband.band1.bytes=5697
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=5697
git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetchtree:0200853 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=853
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=fb781d4e4fd58ededa1f1078d937de6f4b1316a2
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=853
git.pkt.payload.max=826
git.sideband.band1.bytes=826
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=826
git.pack.trailer=c89bc485f6ad08d875fc515f3fdd69897096847b
Open pack map
fetch2002.5 KiB379 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=379
git.response.bytes=2570
git.response.cache=MISS
git.response.duration_ms=379
git.fetch.wants=d216735913ba653a618d327f1a0332d82ed0a26b
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2570
git.pkt.payload.max=2543
git.sideband.band1.bytes=2543
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://github.com/ivarvong/ply
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e14c6968eba140
Request
a10afd34…
Protocol
v2 · sha1
Agent
git/github-9922ec520325-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format