Artifactspublic-v0

ply

main
ply4 git calls349 ms40 KiB1 cachedprotocol v2
89 lines6.5 KiBRaw
1// An error never grows with a caller's text: the tree encoder quotes at most 200 UTF-16 units of a name (or a mode)
2// and says the true length. The bound below is derived by hand from the message's shape, not read from the code:
3// `tree: entry "` + 200 units, each at most 6 characters once JSON-escaped (\uXXXX) + `"… (N UTF-16 units)` + `: ` +
4// a fixed reason (the longest is under 100 characters) + a second quoted value of the same shape for a mode.
5// 2 × (200 × 6 + 40) + 200 = 2680 characters, whatever the caller sends.
6import { test } from 'vitest';
7import assert from 'node:assert/strict';
8import { encodeTree, encodeEntries, treeEntryOf } from '../src/objects.js';
10const BLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';
11const BOUND = 2680;
12const QUOTE = 200;
13// every string the error holds: the message and each field
14const held = error => Math.max(error.message.length, ...Object.values(error).filter(v => typeof v === 'string').map(v => v.length));
16test('a tree refusal is the same size for a 5 000 and a 1 000 000 character name: the name is cut to 200 units and its length said', () => {
17 const cells = [
18 ['large pathname', n => ({ mode: '100644', name: 'x'.repeat(n), oid: BLOB })],
19 ['NUL in name', n => ({ mode: '100644', name: `a\0${'B'.repeat(n)}`, oid: BLOB })],
20 ['full pathname', n => ({ mode: '100644', name: `a/${'b'.repeat(n)}`, oid: BLOB })],
21 ['bad name', n => ({ mode: '100644', name: `.git${' '.repeat(n)}`, oid: BLOB })],
22 ['invalid mode, long name', n => ({ mode: '644', name: '\u0001'.repeat(n), oid: BLOB })],
23 ['invalid mode, long mode', n => ({ mode: '7'.repeat(n), name: 'a', oid: BLOB })],
24 ['oid, long name and oid', n => ({ mode: '100644', name: 'é'.repeat(n), oid: 'f'.repeat(n) })],
25 ];
26 const wrong = [];
27 for (const [reason, make] of cells) {
28 for (const [fn, encode] of [['encodeTree', e => encodeTree([e])], ['encodeEntries', e => encodeEntries([e])], ['treeEntryOf', treeEntryOf]]) {
29 const sizes = [];
30 for (const n of [5000, 1000000]) {
31 const entry = make(n);
32 const got = encode(entry);
33 // treeEntryOf checks the mode and the oid only: the name's own refusals are the encoder's
34 if (got.ok) { if (fn !== 'treeEntryOf') wrong.push(`${fn} ${reason} n=${n}: encoded`); continue; }
35 assert.equal(got.error.code, 'bad_request');
36 if (held(got.error) > BOUND) wrong.push(`${fn} ${reason} n=${n}: the error holds a ${held(got.error)}-character string`);
37 if (typeof got.error.entry === 'string' && got.error.entry.length > QUOTE) wrong.push(`${fn} ${reason} n=${n}: entry field is ${got.error.entry.length} units`);
38 // the true length of whatever was cut is in the message
39 for (const text of [entry.name, entry.mode]) {
40 if (text.length > QUOTE && !got.error.message.includes(`(${text.length} UTF-16 units)`)) wrong.push(`${fn} ${reason} n=${n}: the message does not say the length ${text.length}: ${got.error.message.slice(0, 100)}`);
41 }
42 sizes.push(got.error.message.length);
43 }
44 // 5 000 and 1 000 000 differ by three digits in each reported length and by nothing else
45 if (sizes.length === 2 && sizes[1] - sizes[0] > 2 * 3) wrong.push(`${fn} ${reason}: the message grew ${sizes[0]} -> ${sizes[1]}`);
46 }
47 }
48 assert.deepEqual(wrong, []);
49});
51test('a short name is quoted whole, exactly as before; 200 units is not cut and 201 is; a duplicate is cut the same way', () => {
52 const short = encodeTree([{ mode: '100644', name: 'a/b', oid: BLOB }]);
53 assert.deepEqual([short.error.message, short.error.entry], ['tree: entry "a/b": full pathname', 'a/b']);
54 const at = 'n'.repeat(200);
55 const edge = encodeTree([{ mode: '644', name: at, oid: BLOB }]);
56 assert.deepEqual([edge.error.message, edge.error.entry], [`tree: entry "${at}": invalid mode "644"`, at]);
57 const over = encodeTree([{ mode: '644', name: `${at}Z`, oid: BLOB }]);
58 assert.deepEqual([over.error.message, over.error.entry], [`tree: entry "${at}"… (201 UTF-16 units): invalid mode "644"`, at]);
59 const name = 'd'.repeat(3000);
60 const dup = encodeTree([{ mode: '100644', name, oid: BLOB }, { mode: '40000', name, oid: BLOB }]);
61 assert.deepEqual([dup.error.message, dup.error.entry], [`tree: duplicate entry "${'d'.repeat(200)}"… (3000 UTF-16 units)`, 'd'.repeat(200)]);
62});
64test('the cut never ends on the first half of a surrogate pair: a well-formed name gives a well-formed message and `entry`', () => {
65 // By hand: 199 `a`, then U+1F600 (the pair d83d de00, units 199 and 200), then ten `b`: 211 units. A cut at 200 units
66 // ends on d83d alone: a string with no byte form, in an error about a name that has one. The cut stops before the
67 // pair, at 199 units, and the length said is still the name's own.
68 const head = 'a'.repeat(199);
69 const name = `${head}\u{1F600}${'b'.repeat(10)}`;
70 for (const [fn, encode] of [['encodeTree', e => encodeTree([e])], ['encodeEntries', e => encodeEntries([e])], ['treeEntryOf', treeEntryOf]]) {
71 const got = encode({ mode: '644', name, oid: BLOB });
72 assert.deepEqual([got.error.message, got.error.entry], [`tree: entry "${head}"… (211 UTF-16 units): invalid mode "644"`, head], fn);
73 }
74 // a pair that ends exactly at unit 200 is kept whole: 198 `a` and the pair are the 200 units quoted
75 const fits = `${'a'.repeat(198)}\u{1F600}`;
76 const kept = encodeTree([{ mode: '644', name: `${fits}bbb`, oid: BLOB }]);
77 assert.deepEqual([kept.error.message, kept.error.entry], [`tree: entry "${fits}"… (203 UTF-16 units): invalid mode "644"`, fits]);
78 // a mode is cut by the same rule
79 const mode = encodeTree([{ mode: `${'7'.repeat(199)}\u{1F600}7`, name: 'a', oid: BLOB }]);
80 assert.equal(mode.error.message, `tree: entry "a": invalid mode "${'7'.repeat(199)}"… (202 UTF-16 units)`);
81 // The edges of the high-surrogate range, d800 to dbff, at unit 199: U+10000 is d800 dc00 and U+10FFFF is dbff dfff
82 // (cut before them: 199 units). U+D7FF and U+E000 are ordinary characters, and a low surrogate with no high one
83 // before it is the caller's own ill-formed name: none is the first half of a pair, so 200 units are kept.
84 for (const [at, units] of [['\u{10000}', 199], ['\u{10FFFF}', 199], ['퟿b', 200], ['\udc00b', 200], ['b', 200]]) {
85 const got = encodeTree([{ mode: '644', name: `${head}${at}bbbb`, oid: BLOB }]);
86 assert.equal(got.error.entry, `${head}${at}`.slice(0, units), `U+${at.codePointAt(0).toString(16)}`);
87 assert.equal(got.error.entry.isWellFormed(), at.charCodeAt(0) !== 0xdc00, `U+${at.codePointAt(0).toString(16)}`);
88 }
89});
Diagnostics4 git calls · 349 ms
CallStatusSizeTime0349 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
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=343
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
fetch2002.3 KiB343 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2393
git.response.cache=MISS
git.response.duration_ms=343
git.fetch.wants=e8d93d0f97ced7bb5ef7ba079756d4749a5fe3e8
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=2393
git.pkt.payload.max=2372
git.sideband.band1.bytes=2371
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
a5e21afd397becd4
Request
dec1c2ca…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format