team-ljyzipelo

공개

GZip 비교 기준 파일과 통합 출처를 보완

작성자
호시노 히나타
작성 시각
커밋
ba63ba9d464ac415acc17285f4e7e391552678d8
부모
e015332
이 시점의 파일 보기

변경된 파일 10개

+1,502-6
추가tests/gzip-boundary-probe/Program.cs+424-0
@@ -0,0 +1,424 @@
1추가: using System.Buffers.Binary;
2추가: using System.IO.Compression;
3추가: using System.Security.Cryptography;
4추가: using System.Text;
5추가: using ICSharpCode.SharpZipLib.Zip.Compression;
6추가: using Zipelo.GzipBoundaryProbe;
7추가:
8추가: internal static class Program
9추가: {
10추가: private static int passed;
11추가: private static int failed;
12추가:
13추가: public static int Main(string[] args)
14추가: {
15추가: if (args.Length != 0) { return 2; }
16추가: Run("crc.known-vector", () => Equal(Fixture.Crc("123456789"u8), 0xcbf43926U));
17추가: var text = "123456789"u8.ToArray();
18추가: var large = Enumerable.Range(0, 200003).Select(i => (byte)(i * 17)).ToArray();
19추가: foreach (var data in new[] { Array.Empty<byte>(), text, large })
20추가: {
21추가: var fixture = Fixture.Create(data);
22추가: foreach (var feed in new[] { 1, 2, 3, 7, 8, 9, 31, 512, 65536 })
23추가: {
24추가: Run($"valid.{data.Length}.{feed}", () => Verify(fixture, data, feed));
25추가: }
26추가: Run($"unselected.{data.Length}", () =>
27추가: {
28추가: var budget = new ProbeBudget(new(Output: 0));
29추가: var result = BoundaryProbe.Read(fixture.Bytes, budget, false,
30추가: _ => throw new Exception("선택하지 않은 바이트가 전달됨"));
31추가: Equal(result.InflatedBytes, (long)data.Length);
32추가: Equal(budget.Output, 0L);
33추가: Equal(budget.Processed, (long)fixture.Bytes.Length + data.Length);
34추가: });
35추가: }
36추가: foreach (byte flags in Enumerable.Range(0, 32).Select(i => (byte)i))
37추가: {
38추가: var fixture = Fixture.Create(text, flags);
39추가: Run($"header.flags.{flags}", () => Verify(fixture, text, 1));
40추가: }
41추가: foreach (var length in new[] { 65520, 65521, 65535, 65536, 65537, 131073 })
42추가: {
43추가: var data = large[..length];
44추가: var stored = Fixture.Create(data, level: CompressionLevel.NoCompression);
45추가: Run($"boundary.stored-chunks.{length}", () => Verify(stored, data, 65536));
46추가: }
47추가: var basic = Fixture.Create(text);
48추가: Run("boundary.readahead", () =>
49추가: {
50추가: var result = Verify(basic, text, 65536);
51추가: Equal(result.ReadAheadBytes, 8);
52추가: Equal(result.OfferedBytes, (long)basic.RawLength + 8);
53추가: });
54추가: Run("boundary.byte-feed", () =>
55추가: {
56추가: var result = Verify(basic, text, 1);
57추가: Check(result.ReadAheadBytes <= 1);
58추가: });
59추가: foreach (var raw in new[] { new byte[] { 3, 0 }, new byte[] { 1, 0, 0, 255, 255 } })
60추가: {
61추가: var fixture = Fixture.Wrap(raw, [], 0);
62추가: Run($"empty.raw.{raw.Length}", () => Verify(fixture, [], 1));
63추가: }
64추가: Run("empty.fixture.raw-boundary-hash", () =>
65추가: {
66추가: var fixture = Fixture.Create([]);
67추가: Equal(fixture.RawLength, 2);
68추가: Check(fixture.Bytes.AsSpan(fixture.HeaderLength, fixture.RawLength)
69추가: .SequenceEqual(new byte[] { 0x03, 0x00 }));
70추가: Verify(fixture, [], 1);
71추가: Verify(fixture, [], 65536);
72추가: });
73추가: Run("raw.finished-consumed-unread", RawContract);
74추가: Run("crc.known-trailer", () =>
75추가: {
76추가: var trailer = BinaryPrimitives.ReadUInt32LittleEndian(basic.Bytes.AsSpan(basic.Bytes.Length - 8));
77추가: Equal(trailer, 0xcbf43926U);
78추가: });
79추가: foreach (var offset in new[] { 0, 1, 2 })
80추가: {
81추가: Run($"header.invalid.{offset}", () => Reject(Mutate(basic.Bytes, offset), Failure.Header));
82추가: }
83추가: foreach (var bit in new[] { 0x20, 0x40, 0x80 })
84추가: {
85추가: Run($"header.reserved.{bit}", () => Reject(Mutate(basic.Bytes, 3, (byte)bit), Failure.Header));
86추가: }
87추가: for (var i = 0; i < 4; i++)
88추가: {
89추가: var offset = basic.Bytes.Length - 8 + i;
90추가: Run($"crc.byte.{i}", () => Reject(Mutate(basic.Bytes, offset), Failure.Crc));
91추가: offset += 4;
92추가: var sizeOffset = offset;
93추가: Run($"isize.byte.{i}", () => Reject(Mutate(basic.Bytes, sizeOffset), Failure.Size));
94추가: }
95추가: var optional = Fixture.Create(text, 31);
96추가: Run("header.fhcrc", () => Reject(Mutate(optional.Bytes, optional.HeaderLength - 2), Failure.Header));
97추가: Run("header.fhcrc-covers-name", () => Reject(Mutate(optional.Bytes, 18), Failure.Header));
98추가: Run("header.fname-no-path-use", () => Verify(Fixture.Create(text, 8, "../../escape"), text, 7));
99추가: Run("header.unterminated-name", () => Reject([31, 139, 8, 8, 0, 0, 0, 0, 0, 255, 65], Failure.Truncated));
100추가: Run("header.unterminated-comment", () => Reject([31, 139, 8, 16, 0, 0, 0, 0, 0, 255, 65], Failure.Truncated));
101추가: Run("header.extra-truncated", () => Reject([31, 139, 8, 4, 0, 0, 0, 0, 0, 255, 255, 255, 1], Failure.Truncated));
102추가: Run("deflate.invalid-block", () => Reject(Fixture.Wrap([7], [], 0).Bytes, Failure.Deflate));
103추가: Run("deflate.invalid-backreference-history", () =>
104추가: Reject(Fixture.Wrap([0x03, 0x02, 0x00], [0, 0, 0], 0).Bytes, Failure.Deflate));
105추가: Run("deflate.valid-three-zero-bytes", () => Verify(Fixture.Create([0, 0, 0]), [0, 0, 0], 65536));
106추가: foreach (var suffix in new[] { new byte[] { 0 }, new byte[] { 255 }, new byte[512], basic.Bytes,
107추가: Fixture.Create([]).Bytes, new byte[] { 31, 139 } })
108추가: {
109추가: Run($"trailing.{suffix.Length}.{suffix[0]}", () => Reject([.. basic.Bytes, .. suffix], Failure.TrailingData));
110추가: }
111추가: for (var length = 0; length < optional.Bytes.Length; length++)
112추가: {
113추가: var prefix = optional.Bytes[..length];
114추가: Run($"truncate.{length}", () => RejectAny(prefix));
115추가: }
116추가: Run("sink.pending-after-crc-failure", () =>
117추가: {
118추가: using var sink = new HashSink();
119추가: Expect(Failure.Crc, () => BoundaryProbe.Read(Mutate(basic.Bytes, basic.Bytes.Length - 8),
120추가: new(new()), true, sink.Append));
121추가: Equal(sink.Bytes, (long)text.Length);
122추가: Check(sink.CommittedHash == null);
123추가: });
124추가: Run("unselected.bad-crc", () => Reject(Mutate(basic.Bytes, basic.Bytes.Length - 8), Failure.Crc, selected: false));
125추가: Run("unselected.trailing", () => Reject([.. basic.Bytes, 0], Failure.TrailingData, selected: false));
126추가: Run("budget.input", () => Reject(basic.Bytes, Failure.Budget, new(Input: basic.Bytes.Length - 1)));
127추가: Run("budget.processed", () => Reject(basic.Bytes, Failure.Budget,
128추가: new(Processed: basic.Bytes.Length + text.Length - 1)));
129추가: Run("budget.output", () => Reject(basic.Bytes, Failure.Budget, new(Output: text.Length - 1)));
130추가: Run("budget.metadata", () => Reject(optional.Bytes, Failure.Budget, new(Metadata: optional.HeaderLength - 1)));
131추가: Run("budget.exact", () => Verify(optional, text, 65536,
132추가: new(Input: optional.Bytes.Length, Processed: optional.Bytes.Length + text.Length,
133추가: Output: text.Length, Metadata: optional.HeaderLength)));
134추가: Run("budget.metadata-cap", () => Reject(Fixture.Create([], 8, new string('a', 1024 * 1024)).Bytes,
135추가: Failure.Budget, new(Metadata: long.MaxValue)));
136추가: Run("budget.input-cap", () => Reject(new byte[16 * 1024 * 1024 + 1], Failure.Budget, new(Input: long.MaxValue)));
137추가: Run("budget.clamps", () =>
138추가: {
139추가: var budget = new ProbeBudget(new(long.MaxValue, long.MaxValue, long.MaxValue, long.MaxValue, TimeSpan.MaxValue));
140추가: Equal(budget.InputLimit, 16777216L);
141추가: Equal(budget.ProcessedLimit, 134217728L);
142추가: Equal(budget.OutputLimit, 16777216L);
143추가: Equal(budget.MetadataLimit, 1048576L);
144추가: Equal(budget.Duration, TimeSpan.FromMinutes(5));
145추가: });
146추가: Run("budget.cumulative-processed", () =>
147추가: {
148추가: var budget = new ProbeBudget(new(Processed: 2L * (basic.Bytes.Length + text.Length) - 1));
149추가: using var first = new HashSink();
150추가: first.Complete(BoundaryProbe.Read(basic.Bytes, budget, true, first.Append));
151추가: using var second = new HashSink();
152추가: Expect(Failure.Budget, () => BoundaryProbe.Read(basic.Bytes, budget, true, second.Append));
153추가: Check(first.CommittedHash != null && second.CommittedHash == null);
154추가: });
155추가: Run("budget.cumulative-output", () =>
156추가: {
157추가: var budget = new ProbeBudget(new(Output: text.Length));
158추가: BoundaryProbe.Read(basic.Bytes, budget, true, _ => { });
159추가: Expect(Failure.Budget, () => BoundaryProbe.Read(basic.Bytes, budget, true, _ => { }));
160추가: });
161추가: Run("budget.cumulative-metadata", () =>
162추가: {
163추가: var budget = new ProbeBudget(new(Metadata: basic.HeaderLength));
164추가: BoundaryProbe.Read(basic.Bytes, budget, false, _ => { });
165추가: Expect(Failure.Budget, () => BoundaryProbe.Read(basic.Bytes, budget, false, _ => { }));
166추가: });
167추가: Run("budget.unselected-expansion", () => Reject(Fixture.Create(large).Bytes, Failure.Budget,
168추가: new(Processed: 10000), selected: false));
169추가: Run("budget.deadline", () =>
170추가: {
171추가: var clock = new ManualClock();
172추가: var budget = new ProbeBudget(new(Duration: TimeSpan.FromSeconds(1)), clock);
173추가: clock.Advance(TimeSpan.FromSeconds(1));
174추가: Expect(Failure.Budget, () => BoundaryProbe.Read(basic.Bytes, budget, false, _ => { }));
175추가: });
176추가: Run("budget.sink-time", () =>
177추가: {
178추가: var clock = new ManualClock();
179추가: var budget = new ProbeBudget(new(Duration: TimeSpan.FromSeconds(1)), clock);
180추가: Expect(Failure.Budget, () => BoundaryProbe.Read(basic.Bytes, budget, true,
181추가: _ => clock.Advance(TimeSpan.FromSeconds(1))));
182추가: });
183추가: Run("cancel.before", () =>
184추가: {
185추가: using var cts = new CancellationTokenSource();
186추가: cts.Cancel();
187추가: ExpectCanceled(() => BoundaryProbe.Read(basic.Bytes, new(new()), true, _ => { }, cts.Token));
188추가: });
189추가: Run("cancel.sink", () =>
190추가: {
191추가: using var cts = new CancellationTokenSource();
192추가: using var sink = new HashSink();
193추가: ExpectCanceled(() => BoundaryProbe.Read(basic.Bytes, new(new()), true,
194추가: bytes => { sink.Append(bytes); cts.Cancel(); }, cts.Token));
195추가: Check(sink.Bytes > 0 && sink.CommittedHash == null);
196추가: });
197추가: Run("cancel.unselected-inflater", () =>
198추가: {
199추가: using var cts = new CancellationTokenSource();
200추가: ExpectCanceled(() => BoundaryProbe.Read(basic.Bytes, new(new()), false, _ => { }, cts.Token,
201추가: inflater: new CancelInflater(cts)));
202추가: });
203추가: Run("sink.exception", () =>
204추가: {
205추가: var sentinel = new InvalidOperationException("시험 수신기 실패");
206추가: try { BoundaryProbe.Read(basic.Bytes, new(new()), true, _ => throw sentinel); }
207추가: catch (InvalidOperationException error) when (ReferenceEquals(error, sentinel)) { return; }
208추가: throw new Exception("수신기 예외가 보존되지 않음");
209추가: });
210추가: Run("inflater.no-progress", () => Expect(Failure.NoProgress, () =>
211추가: BoundaryProbe.Read(basic.Bytes, new(new()), true, _ => { }, inflater: new StalledInflater())));
212추가: Run("inflater.contract-violation", () => Expect(Failure.Boundary, () =>
213추가: BoundaryProbe.Read(basic.Bytes, new(new()), true, _ => { }, inflater: new BrokenInflater())));
214추가: Console.WriteLine($"passed={passed} failed={failed}");
215추가: return failed == 0 ? 0 : 1;
216추가: }
217추가:
218추가: private static BoundaryResult Verify(Fixture fixture, byte[] plain, int feed, Limits? limits = null)
219추가: {
220추가: using var sink = new HashSink();
221추가: var budget = new ProbeBudget(limits ?? new());
222추가: var result = BoundaryProbe.Read(fixture.Bytes, budget, true, sink.Append, feedSize: feed);
223추가: Check(sink.CommittedHash == null);
224추가: sink.Complete(result);
225추가: Equal(sink.CommittedHash!, Convert.ToHexString(SHA256.HashData(plain)));
226추가: Equal(result.HeaderBytes, fixture.HeaderLength);
227추가: Equal(result.DeflateBytes, (long)fixture.RawLength);
228추가: Equal(result.InflatedBytes, (long)plain.Length);
229추가: Equal(result.InflaterTotalOut, (long)plain.Length);
230추가: Equal(result.MemberBytes, fixture.Bytes.Length);
231추가: Equal(result.OfferedBytes - result.ReadAheadBytes, result.DeflateBytes);
232추가: Equal(budget.Processed, (long)fixture.Bytes.Length + plain.Length);
233추가: Equal(budget.Metadata, (long)fixture.HeaderLength);
234추가: Equal(budget.Output, (long)plain.Length);
235추가: Check(sink.MaxChunk <= ProbeBudget.ChunkSize);
236추가: return result;
237추가: }
238추가:
239추가: private static void RawContract()
240추가: {
241추가: var data = Enumerable.Repeat((byte)65, 16384).ToArray();
242추가: var fixture = Fixture.Create(data);
243추가: var raw = fixture.Bytes.AsSpan(fixture.HeaderLength, fixture.RawLength).ToArray();
244추가: byte[] input = [.. raw, 11, 22, 33, 44, 55, 66, 77, 88];
245추가: var inflater = new Inflater(true);
246추가: inflater.SetInput(input);
247추가: var output = new byte[1];
248추가: var count = 0;
249추가: var pendingObserved = false;
250추가: while (!inflater.IsFinished)
251추가: {
252추가: Check(count <= data.Length);
253추가: var before = inflater.TotalIn;
254추가: var n = inflater.Inflate(output);
255추가: Check(n == 1 || inflater.IsFinished || inflater.TotalIn > before);
256추가: if (n == 1) { Equal(output[0], (byte)65); count++; }
257추가: Equal(inflater.TotalIn + inflater.RemainingInput, (long)input.Length);
258추가: if (count < data.Length && inflater.RemainingInput >= 8) { pendingObserved |= !inflater.IsFinished; }
259추가: }
260추가: Equal(count, data.Length);
261추가: Equal(inflater.TotalIn, (long)raw.Length);
262추가: Equal(inflater.RemainingInput, 8);
263추가: Equal(inflater.TotalOut, (long)data.Length);
264추가: Check(pendingObserved);
265추가: Check(input.AsSpan(input.Length - inflater.RemainingInput).SequenceEqual(new byte[] { 11, 22, 33, 44, 55, 66, 77, 88 }));
266추가: }
267추가:
268추가: private static void Reject(byte[] input, Failure failure, Limits? limits = null, bool selected = true)
269추가: {
270추가: using var sink = new HashSink();
271추가: Expect(failure, () => BoundaryProbe.Read(input, new(limits ?? new()), selected, sink.Append));
272추가: Check(sink.CommittedHash == null);
273추가: }
274추가:
275추가: private static void RejectAny(byte[] input)
276추가: {
277추가: using var sink = new HashSink();
278추가: try { BoundaryProbe.Read(input, new(new()), true, sink.Append, feedSize: 1); }
279추가: catch (ProbeException error) when (error.Failure is Failure.Header or Failure.Truncated or Failure.Deflate or Failure.Crc or Failure.Size)
280추가: {
281추가: Check(sink.CommittedHash == null);
282추가: return;
283추가: }
284추가: throw new Exception("잘린 입력이 거부되지 않음");
285추가: }
286추가:
287추가: private static byte[] Mutate(byte[] input, int offset, byte mask = 1)
288추가: {
289추가: var copy = (byte[])input.Clone();
290추가: copy[offset] ^= mask;
291추가: return copy;
292추가: }
293추가:
294추가: private static void Expect(Failure failure, Action action)
295추가: {
296추가: try { action(); }
297추가: catch (ProbeException error) when (error.Failure == failure) { return; }
298추가: throw new Exception($"예상 실패 없음: {failure}");
299추가: }
300추가:
301추가: private static void ExpectCanceled(Action action)
302추가: {
303추가: try { action(); }
304추가: catch (OperationCanceledException) { return; }
305추가: throw new Exception("취소가 전파되지 않음");
306추가: }
307추가:
308추가: private static void Run(string name, Action action)
309추가: {
310추가: try { action(); passed++; Console.WriteLine($"PASS {name}"); }
311추가: catch (Exception error) { failed++; Console.WriteLine($"FAIL {name}: {error.GetType().Name}: {error.Message}"); }
312추가: }
313추가:
314추가: private static void Check(bool value)
315추가: {
316추가: if (!value) { throw new Exception("검사 실패"); }
317추가: }
318추가:
319추가: private static void Equal<T>(T actual, T expected) where T : notnull => Check(EqualityComparer<T>.Default.Equals(actual, expected));
320추가: }
321추가:
322추가: internal sealed class HashSink : IDisposable
323추가: {
324추가: private readonly IncrementalHash hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256);
325추가: public long Bytes { get; private set; }
326추가: public int MaxChunk { get; private set; }
327추가: public string? CommittedHash { get; private set; }
328추가:
329추가: public void Append(ReadOnlyMemory<byte> bytes)
330추가: {
331추가: if (CommittedHash != null || bytes.Length > ProbeBudget.ChunkSize) { throw new InvalidOperationException(); }
332추가: hash.AppendData(bytes.Span);
333추가: Bytes += bytes.Length;
334추가: MaxChunk = Math.Max(MaxChunk, bytes.Length);
335추가: }
336추가:
337추가: public void Complete(BoundaryResult result)
338추가: {
339추가: if (Bytes != result.InflatedBytes || CommittedHash != null) { throw new InvalidOperationException(); }
340추가: CommittedHash = Convert.ToHexString(hash.GetHashAndReset());
341추가: }
342추가:
343추가: public void Dispose() => hash.Dispose();
344추가: }
345추가:
346추가: internal sealed record Fixture(byte[] Bytes, int HeaderLength, int RawLength)
347추가: {
348추가: public static Fixture Create(byte[] plain, byte flags = 0, string name = "sample.txt",
349추가: CompressionLevel level = CompressionLevel.Optimal)
350추가: {
351추가: if (plain.Length == 0)
352추가: {
353추가: return Wrap([0x03, 0x00], plain, flags, name);
354추가: }
355추가: using var raw = new MemoryStream();
356추가: using (var compressor = new DeflateStream(raw, level, true)) { compressor.Write(plain); }
357추가: return Wrap(raw.ToArray(), plain, flags, name);
358추가: }
359추가:
360추가: public static Fixture Wrap(byte[] raw, byte[] plain, byte flags, string name = "sample.txt")
361추가: {
362추가: using var output = new MemoryStream();
363추가: output.Write(new byte[] { 31, 139, 8, flags, 0, 0, 0, 0, 0, 255 });
364추가: if ((flags & 4) != 0) { output.Write(new byte[] { 4, 0, 11, 22, 33, 44 }); }
365추가: if ((flags & 8) != 0) { output.Write(Encoding.Latin1.GetBytes(name)); output.WriteByte(0); }
366추가: if ((flags & 16) != 0) { output.Write("comment"u8); output.WriteByte(0); }
367추가: if ((flags & 2) != 0)
368추가: {
369추가: var crc = Crc(output.ToArray());
370추가: output.WriteByte((byte)crc);
371추가: output.WriteByte((byte)(crc >> 8));
372추가: }
373추가: var header = (int)output.Length;
374추가: output.Write(raw);
375추가: Span<byte> trailer = stackalloc byte[8];
376추가: BinaryPrimitives.WriteUInt32LittleEndian(trailer, Crc(plain));
377추가: BinaryPrimitives.WriteUInt32LittleEndian(trailer[4..], (uint)plain.Length);
378추가: output.Write(trailer);
379추가: return new(output.ToArray(), header, raw.Length);
380추가: }
381추가:
382추가: // 시험 기대값은 라이브러리 CRC 구현과 독립적으로 계산함.
383추가: public static uint Crc(ReadOnlySpan<byte> bytes)
384추가: {
385추가: var crc = uint.MaxValue;
386추가: foreach (var value in bytes)
387추가: {
388추가: crc ^= value;
389추가: for (var bit = 0; bit < 8; bit++) { crc = (crc >> 1) ^ ((crc & 1) == 0 ? 0U : 0xedb88320U); }
390추가: }
391추가: return ~crc;
392추가: }
393추가: }
394추가:
395추가: internal sealed class ManualClock : TimeProvider
396추가: {
397추가: private long ticks;
398추가: public override long TimestampFrequency => TimeSpan.TicksPerSecond;
399추가: public override long GetTimestamp() => ticks;
400추가: public void Advance(TimeSpan duration) => ticks += duration.Ticks;
401추가: }
402추가:
403추가: internal class StalledInflater : IRawInflater
404추가: {
405추가: protected int supplied;
406추가: public bool IsFinished => false;
407추가: public bool IsNeedingInput => supplied == 0;
408추가: public bool IsNeedingDictionary => false;
409추가: public virtual long TotalIn => 0;
410추가: public long TotalOut => 0;
411추가: public int RemainingInput => supplied;
412추가: public void SetInput(byte[] bytes, int count) => supplied += count;
413추가: public virtual int Inflate(byte[] output) => 0;
414추가: }
415추가:
416추가: internal sealed class BrokenInflater : StalledInflater
417추가: {
418추가: public override long TotalIn => supplied == 0 ? 0 : supplied + 1L;
419추가: }
420추가:
421추가: internal sealed class CancelInflater(CancellationTokenSource cts) : StalledInflater
422추가: {
423추가: public override int Inflate(byte[] output) { cts.Cancel(); return 0; }
424추가: }
추가tests/gzip-history-integration-probe/BoundaryProbe.cs+290-0
@@ -0,0 +1,290 @@
1추가: using System.Buffers.Binary;
2추가: using ICSharpCode.SharpZipLib;
3추가: using ICSharpCode.SharpZipLib.Checksum;
4추가: using ICSharpCode.SharpZipLib.Zip.Compression;
5추가:
6추가: namespace Zipelo.GzipBoundaryProbe;
7추가:
8추가: internal enum Failure
9추가: {
10추가: Header, Truncated, Deflate, Boundary, Crc, Size, TrailingData, Budget, NoProgress
11추가: }
12추가:
13추가: internal sealed class ProbeException(Failure failure) : Exception(failure.ToString())
14추가: {
15추가: public Failure Failure { get; } = failure;
16추가: }
17추가:
18추가: internal sealed record Limits(
19추가: long Input = 16L * 1024 * 1024,
20추가: long Processed = 128L * 1024 * 1024,
21추가: long Output = 16L * 1024 * 1024,
22추가: long Metadata = 1024 * 1024,
23추가: TimeSpan? Duration = null);
24추가:
25추가: // 여러 순회의 처리량과 선택 출력, 메타데이터 및 시간을 누적함.
26추가: internal sealed class ProbeBudget
27추가: {
28추가: public const int ChunkSize = 65536;
29추가: public long InputLimit { get; }
30추가: public long ProcessedLimit { get; }
31추가: public long OutputLimit { get; }
32추가: public long MetadataLimit { get; }
33추가: public TimeSpan Duration { get; }
34추가: public long Processed { get; private set; }
35추가: public long Output { get; private set; }
36추가: public long Metadata { get; private set; }
37추가: private readonly TimeProvider clock;
38추가: private readonly long started;
39추가:
40추가: public ProbeBudget(Limits limits, TimeProvider? clock = null)
41추가: {
42추가: if (limits.Input < 0 || limits.Processed < 0 || limits.Output < 0 || limits.Metadata < 0 ||
43추가: limits.Duration is { } duration && duration <= TimeSpan.Zero)
44추가: {
45추가: throw new ArgumentOutOfRangeException(nameof(limits));
46추가: }
47추가: InputLimit = Math.Min(limits.Input, 16L * 1024 * 1024);
48추가: ProcessedLimit = Math.Min(limits.Processed, 128L * 1024 * 1024);
49추가: OutputLimit = Math.Min(limits.Output, 16L * 1024 * 1024);
50추가: MetadataLimit = Math.Min(limits.Metadata, 1024 * 1024);
51추가: Duration = limits.Duration is { } requested && requested < TimeSpan.FromMinutes(5)
52추가: ? requested : TimeSpan.FromMinutes(5);
53추가: this.clock = clock ?? TimeProvider.System;
54추가: started = this.clock.GetTimestamp();
55추가: }
56추가:
57추가: public void Check(CancellationToken token)
58추가: {
59추가: token.ThrowIfCancellationRequested();
60추가: if (Processed > ProcessedLimit || clock.GetElapsedTime(started) >= Duration) { throw new ProbeException(Failure.Budget); }
61추가: }
62추가:
63추가: public void ChargeProcessed(int count)
64추가: {
65추가: if (count < 0 || count > ProcessedLimit - Processed) { throw new ProbeException(Failure.Budget); }
66추가: Processed += count;
67추가: }
68추가:
69추가: // 이미 생성된 출력은 한도 초과 시에도 기록하며 이후 호출을 차단함.
70추가: public void ChargeDecoded(int count)
71추가: {
72추가: if (count < 0 || count > ChunkSize) { throw new ProbeException(Failure.Boundary); }
73추가: if (Processed > ProcessedLimit) { throw new ProbeException(Failure.Budget); }
74추가: Processed += count;
75추가: if (Processed > ProcessedLimit) { throw new ProbeException(Failure.Budget); }
76추가: }
77추가:
78추가: public void ChargeOutput(int count)
79추가: {
80추가: if (count < 0 || count > OutputLimit - Output) { throw new ProbeException(Failure.Budget); }
81추가: Output += count;
82추가: }
83추가:
84추가: public void ChargeMetadata()
85추가: {
86추가: if (Metadata >= MetadataLimit) { throw new ProbeException(Failure.Budget); }
87추가: Metadata++;
88추가: }
89추가: }
90추가:
91추가: // 시험용 어댑터이며 생산 코드에서 참조하지 않음.
92추가: internal interface IRawInflater
93추가: {
94추가: bool IsFinished { get; }
95추가: bool IsNeedingInput { get; }
96추가: bool IsNeedingDictionary { get; }
97추가: long TotalIn { get; }
98추가: long TotalOut { get; }
99추가: int RemainingInput { get; }
100추가: void SetInput(byte[] bytes, int count);
101추가: int Inflate(byte[] output);
102추가: }
103추가:
104추가: internal sealed class SharpInflater : IRawInflater
105추가: {
106추가: private readonly Inflater inflater = new(true);
107추가: public bool IsFinished => inflater.IsFinished;
108추가: public bool IsNeedingInput => inflater.IsNeedingInput;
109추가: public bool IsNeedingDictionary => inflater.IsNeedingDictionary;
110추가: public long TotalIn => inflater.TotalIn;
111추가: public long TotalOut => inflater.TotalOut;
112추가: public int RemainingInput => inflater.RemainingInput;
113추가: public void SetInput(byte[] bytes, int count) => inflater.SetInput(bytes, 0, count);
114추가: public int Inflate(byte[] output) => inflater.Inflate(output, 0, output.Length);
115추가: }
116추가:
117추가: internal sealed record BoundaryResult(
118추가: int HeaderBytes, long DeflateBytes, int ReadAheadBytes, long InflatedBytes,
119추가: uint Crc32, int MemberBytes, long OfferedBytes, long InflaterTotalOut);
120추가:
121추가: internal static class BoundaryProbe
122추가: {
123추가: // 입력 메모리는 호출 동안 불변이어야 함. 수신 청크는 성공 반환 전까지 임시 결과임.
124추가: public static BoundaryResult Read(ReadOnlyMemory<byte> input, ProbeBudget budget,
125추가: bool selected, Action<ReadOnlyMemory<byte>> sink, CancellationToken token = default,
126추가: int feedSize = ProbeBudget.ChunkSize, IRawInflater? inflater = null)
127추가: {
128추가: ArgumentNullException.ThrowIfNull(budget);
129추가: ArgumentNullException.ThrowIfNull(sink);
130추가: if (feedSize is < 1 or > ProbeBudget.ChunkSize) { throw new ArgumentOutOfRangeException(nameof(feedSize)); }
131추가: budget.Check(token);
132추가: if (input.Length > budget.InputLimit) { throw new ProbeException(Failure.Budget); }
133추가: var cursor = new Cursor(input, budget, token);
134추가: var headerCrc = new Crc32();
135추가: byte HeaderByte()
136추가: {
137추가: budget.Check(token);
138추가: budget.ChargeMetadata();
139추가: var value = cursor.Byte();
140추가: headerCrc.Update(value);
141추가: return value;
142추가: }
143추가: if (HeaderByte() != 0x1f || HeaderByte() != 0x8b || HeaderByte() != 8)
144추가: {
145추가: throw new ProbeException(Failure.Header);
146추가: }
147추가: var flags = HeaderByte();
148추가: if ((flags & 0xe0) != 0) { throw new ProbeException(Failure.Header); }
149추가: for (var i = 0; i < 6; i++) { HeaderByte(); }
150추가: if ((flags & 4) != 0)
151추가: {
152추가: var length = HeaderByte() | (HeaderByte() << 8);
153추가: for (var i = 0; i < length; i++) { HeaderByte(); }
154추가: }
155추가: if ((flags & 8) != 0) { while (HeaderByte() != 0) { } }
156추가: if ((flags & 16) != 0) { while (HeaderByte() != 0) { } }
157추가: if ((flags & 2) != 0)
158추가: {
159추가: var expected = (ushort)headerCrc.Value;
160추가: budget.ChargeMetadata();
161추가: var low = cursor.Byte();
162추가: budget.ChargeMetadata();
163추가: var high = cursor.Byte();
164추가: if ((low | (high << 8)) != expected) { throw new ProbeException(Failure.Header); }
165추가: }
166추가: var headerBytes = cursor.Position;
167추가: inflater ??= new SharpInflater();
168추가: if (inflater.TotalIn != 0 || inflater.TotalOut != 0 || inflater.RemainingInput != 0 || inflater.IsFinished)
169추가: {
170추가: throw new ProbeException(Failure.Boundary);
171추가: }
172추가: var compressed = new byte[ProbeBudget.ChunkSize];
173추가: var output = new byte[ProbeBudget.ChunkSize];
174추가: var crc = new Crc32();
175추가: long offered = 0;
176추가: long decoded = 0;
177추가: while (!inflater.IsFinished)
178추가: {
179추가: budget.Check(token);
180추가: if (inflater.IsNeedingDictionary) { throw new ProbeException(Failure.Deflate); }
181추가: if (inflater.IsNeedingInput)
182추가: {
183추가: var count = cursor.Copy(compressed, feedSize);
184추가: if (count == 0) { throw new ProbeException(Failure.Truncated); }
185추가: inflater.SetInput(compressed, count);
186추가: offered += count;
187추가: }
188추가: var before = inflater.TotalIn;
189추가: var beforeOut = inflater.TotalOut;
190추가: int written;
191추가: try { written = inflater.Inflate(output); }
192추가: catch (SharpZipBaseException) { throw new ProbeException(Failure.Deflate); }
193추가: finally
194추가: {
195추가: // 예외와 반환 직후 취소보다 먼저 실제 출력 증가분을 누적함.
196추가: var produced = inflater.TotalOut - beforeOut;
197추가: if (produced < 0 || produced > output.Length) { throw new ProbeException(Failure.Boundary); }
198추가: budget.ChargeDecoded((int)produced);
199추가: }
200추가: budget.Check(token);
201추가: if (written < 0 || written > output.Length || inflater.TotalIn < before ||
202추가: inflater.TotalIn > offered || inflater.RemainingInput < 0 ||
203추가: inflater.TotalIn != offered - inflater.RemainingInput ||
204추가: inflater.TotalOut != decoded + written)
205추가: {
206추가: throw new ProbeException(Failure.Boundary);
207추가: }
208추가: if (written > 0)
209추가: {
210추가: decoded += written;
211추가: crc.Update(new ArraySegment<byte>(output, 0, written));
212추가: if (selected)
213추가: {
214추가: budget.ChargeOutput(written);
215추가: sink(output.AsMemory(0, written));
216추가: budget.Check(token);
217추가: }
218추가: }
219추가: if (written == 0 && inflater.TotalIn == before && !inflater.IsFinished && !inflater.IsNeedingInput)
220추가: {
221추가: throw new ProbeException(Failure.NoProgress);
222추가: }
223추가: }
224추가: budget.Check(token);
225추가: if (inflater.IsNeedingDictionary || inflater.TotalIn != offered - inflater.RemainingInput ||
226추가: inflater.TotalOut != decoded)
227추가: {
228추가: throw new ProbeException(Failure.Boundary);
229추가: }
230추가: var readAhead = inflater.RemainingInput;
231추가: var boundary = checked(headerBytes + (int)inflater.TotalIn);
232추가: if (cursor.Position - boundary != readAhead) { throw new ProbeException(Failure.Boundary); }
233추가: // 원본 메모리의 미소비 꼬리를 다시 읽음. 선행 읽기 바이트를 중복 과금하지 않음.
234추가: cursor.Rewind(boundary);
235추가: Span<byte> trailer = stackalloc byte[8];
236추가: for (var i = 0; i < trailer.Length; i++) { trailer[i] = cursor.Byte(); }
237추가: if (BinaryPrimitives.ReadUInt32LittleEndian(trailer) != (uint)crc.Value)
238추가: {
239추가: throw new ProbeException(Failure.Crc);
240추가: }
241추가: if (BinaryPrimitives.ReadUInt32LittleEndian(trailer[4..]) != unchecked((uint)decoded))
242추가: {
243추가: throw new ProbeException(Failure.Size);
244추가: }
245추가: // 연결 member는 GZip 규격에서 유효하지만 이 실험의 단일 member 범위에서는 거부함.
246추가: if (cursor.Position != input.Length) { throw new ProbeException(Failure.TrailingData); }
247추가: budget.Check(token);
248추가: return new(headerBytes, inflater.TotalIn, readAhead, decoded, (uint)crc.Value,
249추가: cursor.Position, offered, inflater.TotalOut);
250추가: }
251추가:
252추가: private sealed class Cursor(ReadOnlyMemory<byte> input, ProbeBudget budget, CancellationToken token)
253추가: {
254추가: public int Position { get; private set; }
255추가: private int highWater;
256추가:
257추가: public byte Byte()
258추가: {
259추가: budget.Check(token);
260추가: if (Position == input.Length) { throw new ProbeException(Failure.Truncated); }
261추가: Account(Position + 1);
262추가: return input.Span[Position++];
263추가: }
264추가:
265추가: public int Copy(byte[] destination, int max)
266추가: {
267추가: budget.Check(token);
268추가: var count = Math.Min(max, input.Length - Position);
269추가: Account(Position + count);
270추가: input.Span.Slice(Position, count).CopyTo(destination);
271추가: Position += count;
272추가: return count;
273추가: }
274추가:
275추가: public void Rewind(int position)
276추가: {
277추가: if (position < 0 || position > Position) { throw new ProbeException(Failure.Boundary); }
278추가: Position = position;
279추가: }
280추가:
281추가: private void Account(int end)
282추가: {
283추가: if (end > highWater)
284추가: {
285추가: budget.ChargeProcessed(end - highWater);
286추가: highWater = end;
287추가: }
288추가: }
289추가: }
290추가: }
추가tests/gzip-history-integration-probe/BudgetRegression.cs+141-0
@@ -0,0 +1,141 @@
1추가: using Zipelo.GzipBoundaryProbe;
2추가:
3추가: internal static class BudgetRegression
4추가: {
5추가: public static void Register(Action<string, Action> run)
6추가: {
7추가: var malformed = Fixture.Wrap([0x00, 0x01, 0x00, 0xfe, 0xff, 0x41, 0x07], [0x41], 0);
8추가: var valid = Fixture.Wrap([0x01, 0x01, 0x00, 0xfe, 0xff, 0x41], [0x41], 0);
9추가: foreach (var selected in new[] { false, true })
10추가: {
11추가: run($"accounting.decoder-exception.{selected}", () =>
12추가: {
13추가: var budget = new ProbeBudget(new(Processed: malformed.Bytes.Length + 1));
14추가: var observer = new ObservedInflater();
15추가: var pending = new PendingValidation();
16추가: ExpectFailure(Failure.Deflate, () => pending.Execute(malformed.Bytes, budget, selected, inflater: observer));
17추가: Check(observer.TotalOut == 1 && budget.Processed == malformed.Bytes.Length + 1);
18추가: Check(budget.Output == 0);
19추가: Uncommitted(pending);
20추가: RejectNext(budget, selected);
21추가: });
22추가: run($"accounting.exception-over-limit.{selected}", () =>
23추가: {
24추가: var budget = new ProbeBudget(new(Processed: malformed.Bytes.Length));
25추가: var pending = new PendingValidation();
26추가: ExpectFailure(Failure.Budget, () => pending.Execute(malformed.Bytes, budget, selected));
27추가: Check(budget.Processed == budget.ProcessedLimit + 1);
28추가: Uncommitted(pending);
29추가: RejectNext(budget, selected);
30추가: });
31추가: run($"accounting.return-cancel.{selected}", () =>
32추가: {
33추가: using var cts = new CancellationTokenSource();
34추가: var budget = new ProbeBudget(new(Processed: valid.Bytes.Length + 1));
35추가: var observer = new ObservedInflater(cts.Cancel);
36추가: var pending = new PendingValidation();
37추가: Expect<OperationCanceledException>(() => pending.Execute(valid.Bytes, budget, selected,
38추가: cts.Token, inflater: observer));
39추가: Check(observer.TotalOut == 1 && budget.Processed == valid.Bytes.Length + 1);
40추가: Check(budget.Output == 0);
41추가: Uncommitted(pending);
42추가: RejectNext(budget, selected);
43추가: });
44추가: run($"accounting.return-deadline.{selected}", () =>
45추가: {
46추가: var clock = new ManualClock();
47추가: var budget = new ProbeBudget(new(Duration: TimeSpan.FromSeconds(1)), clock);
48추가: var observer = new ObservedInflater(() => clock.Advance(TimeSpan.FromSeconds(1)));
49추가: var pending = new PendingValidation();
50추가: ExpectFailure(Failure.Budget, () => pending.Execute(valid.Bytes, budget, selected, inflater: observer));
51추가: Check(observer.TotalOut == 1 && budget.Processed == valid.Bytes.Length + 1);
52추가: Check(budget.Output == 0);
53추가: Uncommitted(pending);
54추가: RejectNext(budget, selected);
55추가: });
56추가: run($"accounting.other-exception.{selected}", () =>
57추가: {
58추가: var budget = new ProbeBudget(new(Processed: valid.Bytes.Length + 1));
59추가: var observer = new ObservedInflater(() => throw new IOException("시험 어댑터 실패"));
60추가: var pending = new PendingValidation();
61추가: Expect<IOException>(() => pending.Execute(valid.Bytes, budget, selected, inflater: observer));
62추가: Check(observer.TotalOut == 1 && budget.Processed == valid.Bytes.Length + 1);
63추가: Check(budget.Output == 0);
64추가: Uncommitted(pending);
65추가: RejectNext(budget, selected);
66추가: });
67추가: }
68추가: }
69추가:
70추가: private static void RejectNext(ProbeBudget budget, bool selected)
71추가: {
72추가: var processed = budget.Processed;
73추가: var metadata = budget.Metadata;
74추가: var next = new PendingValidation();
75추가: var observer = new ObservedInflater();
76추가: ExpectFailure(Failure.Budget, () => next.Execute(Fixture.Wrap([3, 0], [], 0).Bytes,
77추가: budget, selected, inflater: observer));
78추가: Check(budget.Processed == processed && budget.Output == 0);
79추가: Check(budget.Metadata >= metadata && observer.Calls == 0);
80추가: Uncommitted(next);
81추가: }
82추가:
83추가: private static void Uncommitted(PendingValidation pending) =>
84추가: Check(pending.CommitCount == 0 && pending.CommittedHash == null && pending.CommittedBoundary == null);
85추가:
86추가: private static void ExpectFailure(Failure failure, Action action)
87추가: {
88추가: try
89추가: {
90추가: action();
91추가: }
92추가: catch (ProbeException error) when (error.Failure == failure)
93추가: {
94추가: return;
95추가: }
96추가: throw new Exception($"예상 실패 없음: {failure}");
97추가: }
98추가:
99추가: private static void Expect<T>(Action action) where T : Exception
100추가: {
101추가: try
102추가: {
103추가: action();
104추가: }
105추가: catch (T)
106추가: {
107추가: return;
108추가: }
109추가: throw new Exception($"예상 예외 없음: {typeof(T).Name}");
110추가: }
111추가:
112추가: private static void Check(bool condition)
113추가: {
114추가: if (!condition)
115추가: {
116추가: throw new Exception("실패 경로의 누적 예산 검사 실패");
117추가: }
118추가: }
119추가: }
120추가:
121추가: // 실제 inflater 반환 직후의 취소와 기한 경계를 시험함.
122추가: internal sealed class ObservedInflater(Action? afterReturn = null) : IRawInflater
123추가: {
124추가: private readonly SharpInflater inner = new();
125추가: public int Calls { get; private set; }
126추가: public bool IsFinished => inner.IsFinished;
127추가: public bool IsNeedingInput => inner.IsNeedingInput;
128추가: public bool IsNeedingDictionary => inner.IsNeedingDictionary;
129추가: public long TotalIn => inner.TotalIn;
130추가: public long TotalOut => inner.TotalOut;
131추가: public int RemainingInput => inner.RemainingInput;
132추가: public void SetInput(byte[] bytes, int count) => inner.SetInput(bytes, count);
133추가:
134추가: public int Inflate(byte[] output)
135추가: {
136추가: Calls++;
137추가: var written = inner.Inflate(output);
138추가: afterReturn?.Invoke();
139추가: return written;
140추가: }
141추가: }
추가tests/gzip-history-integration-probe/FinalizationRegression.cs+148-0
@@ -0,0 +1,148 @@
1추가: using Zipelo.GzipBoundaryProbe;
2추가:
3추가: internal static class FinalizationRegression
4추가: {
5추가: public static void Register(Action<string, Action> run)
6추가: {
7추가: foreach (var selected in new[] { false, true })
8추가: {
9추가: foreach (var scenario in new[] { "success", "body-budget", "body-cancel", "body-both", "dispose-both" })
10추가: {
11추가: run($"finalization.dispose.{scenario}.{selected}", () =>
12추가: {
13추가: VerifyDispose(selected, scenario, false);
14추가: VerifyDispose(selected, scenario, true);
15추가: });
16추가: }
17추가: foreach (var delta in new long[] { -1, ProbeBudget.ChunkSize + 1 })
18추가: {
19추가: for (var mode = 0; mode < 4; mode++)
20추가: {
21추가: var capturedMode = mode;
22추가: run($"finalization.counter.{delta}.{mode}.{selected}", () =>
23추가: VerifyCounter(selected, delta, capturedMode));
24추가: }
25추가: }
26추가: }
27추가: }
28추가:
29추가: private static void VerifyDispose(bool selected, string scenario, bool throwOnDispose)
30추가: {
31추가: var fixture = Fixture.Wrap([0x01, 0x01, 0x00, 0xfe, 0xff, 0x41], [0x41], 0);
32추가: using var cts = new CancellationTokenSource();
33추가: var clock = new ManualClock();
34추가: var budget = new ProbeBudget(new(Duration: TimeSpan.FromSeconds(1)), clock);
35추가: var pending = new PendingValidation();
36추가: var marker = new IOException("임시 수신기 Dispose 실패");
37추가: var disposeCalls = 0;
38추가: var beforeCommitCalls = 0;
39추가: var bodyBudget = scenario is "body-budget" or "body-both";
40추가: var bodyCancel = scenario is "body-cancel" or "body-both";
41추가: var observer = new ObservedInflater(() =>
42추가: {
43추가: if (bodyBudget) { clock.Advance(TimeSpan.FromSeconds(1)); }
44추가: if (bodyCancel) { cts.Cancel(); }
45추가: });
46추가: var error = Capture(() => pending.Execute(fixture.Bytes, budget, selected, cts.Token,
47추가: beforeCommit: () => beforeCommitCalls++, inflater: observer, onSinkDispose: () =>
48추가: {
49추가: disposeCalls++;
50추가: if (scenario == "dispose-both")
51추가: {
52추가: clock.Advance(TimeSpan.FromSeconds(1));
53추가: cts.Cancel();
54추가: }
55추가: if (throwOnDispose) { throw marker; }
56추가: }));
57추가: Check(disposeCalls == 1 && observer.Calls == 1);
58추가: Check(budget.Processed == fixture.Bytes.Length + 1);
59추가: Check(budget.Output == (selected && !bodyBudget && !bodyCancel ? 1 : 0));
60추가: if (throwOnDispose)
61추가: {
62추가: Check(ReferenceEquals(error, marker) && beforeCommitCalls == 0);
63추가: Uncommitted(pending);
64추가: }
65추가: else if (scenario == "success")
66추가: {
67추가: Check(error == null && beforeCommitCalls == 1 && pending.CommitCount == 1);
68추가: Check(pending.CommittedBoundary != null);
69추가: Check(selected ? pending.CommittedHash != null : pending.CommittedHash == null);
70추가: }
71추가: else
72추가: {
73추가: Check(beforeCommitCalls == (scenario == "dispose-both" ? 1 : 0));
74추가: Check(bodyCancel || scenario == "dispose-both"
75추가: ? error is OperationCanceledException
76추가: : error is ProbeException { Failure: Failure.Budget });
77추가: Uncommitted(pending);
78추가: }
79추가: Check(Capture(() => pending.Execute(fixture.Bytes, budget, selected)) is InvalidOperationException);
80추가: Check(disposeCalls == 1);
81추가: }
82추가:
83추가: private static void VerifyCounter(bool selected, long delta, int mode)
84추가: {
85추가: var fixture = Fixture.Wrap([0x01, 0x01, 0x00, 0xfe, 0xff, 0x41], [0x41], 0);
86추가: using var cts = new CancellationTokenSource();
87추가: var clock = new ManualClock();
88추가: var budget = new ProbeBudget(new(Duration: TimeSpan.FromSeconds(1)), clock);
89추가: var observer = new CounterDeltaInflater(delta, () =>
90추가: {
91추가: if ((mode & 1) != 0) { cts.Cancel(); }
92추가: if ((mode & 2) != 0) { clock.Advance(TimeSpan.FromSeconds(1)); }
93추가: });
94추가: var pending = new PendingValidation();
95추가: var disposeCalls = 0;
96추가: var beforeCommitCalls = 0;
97추가: var error = Capture(() => pending.Execute(fixture.Bytes, budget, selected, cts.Token,
98추가: beforeCommit: () => beforeCommitCalls++, inflater: observer,
99추가: onSinkDispose: () => disposeCalls++));
100추가: Check(error is ProbeException { Failure: Failure.Boundary });
101추가: Check(observer.Calls == 1 && observer.TotalOut == delta && observer.ActualTotalOut == 1);
102추가: Check(budget.Processed == fixture.Bytes.Length && budget.Output == 0);
103추가: Check(disposeCalls == 1 && beforeCommitCalls == 0);
104추가: Uncommitted(pending);
105추가: var overlapping = Capture(() => budget.Check(cts.Token));
106추가: Check((mode & 1) != 0 ? overlapping is OperationCanceledException
107추가: : (mode & 2) != 0 ? overlapping is ProbeException { Failure: Failure.Budget }
108추가: : overlapping == null);
109추가: }
110추가:
111추가: private static Exception? Capture(Action action)
112추가: {
113추가: try { action(); }
114추가: catch (Exception error) { return error; }
115추가: return null;
116추가: }
117추가:
118추가: private static void Uncommitted(PendingValidation pending) =>
119추가: Check(pending.CommitCount == 0 && pending.CommittedBoundary == null && pending.CommittedHash == null);
120추가:
121추가: private static void Check(bool condition)
122추가: {
123추가: if (!condition) { throw new Exception("확정 실패 경계 회귀 실패"); }
124추가: }
125추가: }
126추가:
127추가: // 실제 해제 결과는 유지하고 반환 후 관측 카운터만 변조함.
128추가: internal sealed class CounterDeltaInflater(long delta, Action afterReturn) : IRawInflater
129추가: {
130추가: private readonly SharpInflater inner = new();
131추가: public int Calls { get; private set; }
132추가: public long ActualTotalOut => inner.TotalOut;
133추가: public bool IsFinished => inner.IsFinished;
134추가: public bool IsNeedingInput => inner.IsNeedingInput;
135추가: public bool IsNeedingDictionary => inner.IsNeedingDictionary;
136추가: public long TotalIn => inner.TotalIn;
137추가: public long TotalOut => Calls == 0 ? inner.TotalOut : delta;
138추가: public int RemainingInput => inner.RemainingInput;
139추가: public void SetInput(byte[] bytes, int count) => inner.SetInput(bytes, count);
140추가:
141추가: public int Inflate(byte[] output)
142추가: {
143추가: var written = inner.Inflate(output);
144추가: Calls++;
145추가: afterReturn();
146추가: return written;
147추가: }
148추가: }
추가tests/gzip-history-integration-probe/IntegrationProgram.cs+240-0
@@ -0,0 +1,240 @@
1추가: using System.Reflection;
2추가: using System.Security.Cryptography;
3추가: using Zipelo.GzipBoundaryProbe;
4추가:
5추가: internal static class IntegrationProgram
6추가: {
7추가: private static int passed;
8추가: private static int failed;
9추가:
10추가: public static int Main(string[] args)
11추가: {
12추가: if (args.Length != 0)
13추가: {
14추가: return 2;
15추가: }
16추가:
17추가: Console.WriteLine("candidate.inherited-suite.begin");
18추가: var inheritedExit = Program.Main([]);
19추가: Console.WriteLine($"candidate.inherited-suite.exit={inheritedExit}");
20추가: Run("assembly.identity", () =>
21추가: {
22추가: var field = typeof(SharpInflater).GetField("inflater", BindingFlags.Instance | BindingFlags.NonPublic);
23추가: Check(field?.FieldType == typeof(Inflater));
24추가: Check(typeof(Inflater).Assembly.GetName().Name == "Zipelo.Experimental.SharpZipLibHistoryProbe");
25추가: Check(typeof(SharpZipBaseException).Assembly == typeof(Inflater).Assembly);
26추가: Check(typeof(ICSharpCode.SharpZipLib.Checksum.Crc32).Assembly != typeof(Inflater).Assembly);
27추가: });
28추가:
29추가: var zero = Fixture.Create(new byte[3]);
30추가: var invalidHistory = Fixture.Wrap([3, 2, 0], new byte[3], 0);
31추가: var text = "123456789"u8.ToArray();
32추가: var basic = Fixture.Create(text);
33추가: foreach (var selected in new[] { false, true })
34추가: {
35추가: foreach (var feed in new[] { 1, 2, 3, 7, 65536 })
36추가: {
37추가: var label = $"{selected}.{feed}";
38추가: Run($"valid.controls.{label}", () =>
39추가: {
40추가: Verify(zero, new byte[3], selected, feed);
41추가: Verify(Fixture.Wrap([3, 0], [], 0), [], selected, feed);
42추가: Verify(Fixture.Wrap([1, 0, 0, 255, 255], [], 0), [], selected, feed);
43추가: });
44추가: Run($"reject.history.{label}", () => Reject(invalidHistory.Bytes, Failure.Deflate, selected, feed));
45추가: Run($"reject.crc.{label}", () => Reject(Mutate(basic.Bytes, basic.Bytes.Length - 8), Failure.Crc, selected, feed));
46추가: Run($"reject.size.{label}", () => Reject(Mutate(basic.Bytes, basic.Bytes.Length - 4), Failure.Size, selected, feed));
47추가: Run($"reject.header.{label}", () => Reject(Mutate(basic.Bytes, 0), Failure.Header, selected, feed));
48추가: Run($"reject.trailing.{label}", () => Reject([.. basic.Bytes, 0], Failure.TrailingData, selected, feed));
49추가: Run($"reject.member.{label}", () => Reject([.. basic.Bytes, .. zero.Bytes], Failure.TrailingData, selected, feed));
50추가: Run($"reject.trailer-truncation.{label}", () => Reject(basic.Bytes[..^1], Failure.Truncated, selected, feed));
51추가: }
52추가:
53추가: Run($"final.cancel.{selected}", () =>
54추가: {
55추가: using var cts = new CancellationTokenSource();
56추가: var pending = new PendingValidation();
57추가: Expect<OperationCanceledException>(() => pending.Execute(basic.Bytes, new(new()), selected,
58추가: cts.Token, beforeCommit: cts.Cancel));
59추가: Uncommitted(pending);
60추가: });
61추가: Run($"final.deadline.{selected}", () =>
62추가: {
63추가: var clock = new ManualClock();
64추가: var pending = new PendingValidation();
65추가: var budget = new ProbeBudget(new(Duration: TimeSpan.FromSeconds(1)), clock);
66추가: ExpectFailure(Failure.Budget, () => pending.Execute(basic.Bytes, budget, selected,
67추가: beforeCommit: () => clock.Advance(TimeSpan.FromSeconds(1))));
68추가: Uncommitted(pending);
69추가: });
70추가: Run($"cumulative.processed.{selected}", () =>
71추가: {
72추가: var cost = (long)basic.Bytes.Length + text.Length;
73추가: var budget = new ProbeBudget(new(Processed: cost));
74추가: var first = new PendingValidation();
75추가: first.Execute(basic.Bytes, budget, selected);
76추가: Check(first.CommitCount == 1 && budget.Processed == cost);
77추가: var second = new PendingValidation();
78추가: ExpectFailure(Failure.Budget, () => second.Execute(basic.Bytes, budget, selected));
79추가: Uncommitted(second);
80추가: Check(budget.Processed == cost);
81추가: });
82추가: Run($"cumulative.time.{selected}", () =>
83추가: {
84추가: var clock = new ManualClock();
85추가: var budget = new ProbeBudget(new(Duration: TimeSpan.FromSeconds(1)), clock);
86추가: new PendingValidation().Execute(basic.Bytes, budget, selected);
87추가: clock.Advance(TimeSpan.FromSeconds(1));
88추가: var second = new PendingValidation();
89추가: ExpectFailure(Failure.Budget, () => second.Execute(basic.Bytes, budget, selected));
90추가: Uncommitted(second);
91추가: });
92추가: Run($"failure.discard.{selected}", () =>
93추가: {
94추가: var failedAttempt = Reject(invalidHistory.Bytes, Failure.Deflate, selected, 1);
95추가: Expect<InvalidOperationException>(() => failedAttempt.Execute(zero.Bytes, new(new()), selected));
96추가: Uncommitted(failedAttempt);
97추가: Verify(zero, new byte[3], selected, 1);
98추가: });
99추가: }
100추가:
101추가: foreach (byte flags in Enumerable.Range(0, 32).Select(value => (byte)value))
102추가: {
103추가: Run($"unselected.flags.{flags}", () => Verify(Fixture.Create(text, flags), text, false, 1));
104추가: }
105추가: Run("unselected.all-prefixes", () =>
106추가: {
107추가: var optional = Fixture.Create(text, 31);
108추가: for (var length = 0; length < optional.Bytes.Length; length++)
109추가: {
110추가: var pending = new PendingValidation();
111추가: try
112추가: {
113추가: pending.Execute(optional.Bytes.AsMemory(0, length), new(new()), false, feedSize: 1);
114추가: }
115추가: catch (ProbeException error) when (error.Failure is Failure.Header or Failure.Truncated
116추가: or Failure.Deflate or Failure.Crc or Failure.Size)
117추가: {
118추가: Uncommitted(pending);
119추가: continue;
120추가: }
121추가: throw new Exception("잘린 입력이 거부되지 않음");
122추가: }
123추가: });
124추가: Run("pending.output-failure", () =>
125추가: {
126추가: var pending = new PendingValidation();
127추가: var sentinel = new IOException("시험 수신기 실패");
128추가: try
129추가: {
130추가: pending.Execute(basic.Bytes, new(new()), true, afterChunk: () => throw sentinel);
131추가: }
132추가: catch (IOException error) when (ReferenceEquals(error, sentinel))
133추가: {
134추가: Uncommitted(pending);
135추가: return;
136추가: }
137추가: throw new Exception("수신기 실패가 전파되지 않음");
138추가: });
139추가: Run("pending.output-cancel", () =>
140추가: {
141추가: using var cts = new CancellationTokenSource();
142추가: var pending = new PendingValidation();
143추가: Expect<OperationCanceledException>(() => pending.Execute(basic.Bytes, new(new()), true,
144추가: cts.Token, afterChunk: cts.Cancel));
145추가: Uncommitted(pending);
146추가: });
147추가:
148추가: BudgetRegression.Register(Run);
149추가: FinalizationRegression.Register(Run);
150추가: Console.WriteLine($"candidate.integration passed={passed} failed={failed}");
151추가: return inheritedExit == 0 && failed == 0 ? 0 : 1;
152추가: }
153추가:
154추가: private static void Verify(Fixture fixture, byte[] plain, bool selected, int feed)
155추가: {
156추가: var originalHash = SHA256.HashData(fixture.Bytes);
157추가: var budget = new ProbeBudget(new(Output: selected ? plain.Length : 0));
158추가: var pending = new PendingValidation();
159추가: pending.Execute(fixture.Bytes, budget, selected, feedSize: feed);
160추가: var result = pending.CommittedBoundary ?? throw new Exception("확정 경계 없음");
161추가: Check(pending.CommitCount == 1);
162추가: Check(pending.CommittedHash == (selected ? Convert.ToHexString(SHA256.HashData(plain)) : null));
163추가: Check(result.HeaderBytes == fixture.HeaderLength && result.DeflateBytes == fixture.RawLength);
164추가: Check(result.MemberBytes == fixture.Bytes.Length && result.InflatedBytes == plain.Length);
165추가: Check(result.InflaterTotalOut == plain.Length);
166추가: Check(result.OfferedBytes - result.ReadAheadBytes == result.DeflateBytes);
167추가: Check(budget.Processed == (long)fixture.Bytes.Length + plain.Length);
168추가: Check(budget.Output == (selected ? plain.Length : 0) && budget.Metadata == fixture.HeaderLength);
169추가: Check(originalHash.AsSpan().SequenceEqual(SHA256.HashData(fixture.Bytes)));
170추가: }
171추가:
172추가: private static PendingValidation Reject(byte[] input, Failure expected, bool selected, int feed)
173추가: {
174추가: var originalHash = SHA256.HashData(input);
175추가: var pending = new PendingValidation();
176추가: ExpectFailure(expected, () => pending.Execute(input, new(new()), selected, feedSize: feed));
177추가: Uncommitted(pending);
178추가: Check(originalHash.AsSpan().SequenceEqual(SHA256.HashData(input)));
179추가: return pending;
180추가: }
181추가:
182추가: private static byte[] Mutate(byte[] input, int index)
183추가: {
184추가: var copy = (byte[])input.Clone();
185추가: copy[index] ^= 1;
186추가: return copy;
187추가: }
188추가:
189추가: private static void Uncommitted(PendingValidation pending) =>
190추가: Check(pending.CommitCount == 0 && pending.CommittedHash == null && pending.CommittedBoundary == null);
191추가:
192추가: private static void ExpectFailure(Failure expected, Action action)
193추가: {
194추가: try
195추가: {
196추가: action();
197추가: }
198추가: catch (ProbeException error) when (error.Failure == expected)
199추가: {
200추가: return;
201추가: }
202추가: throw new Exception($"예상 거부 없음: {expected}");
203추가: }
204추가:
205추가: private static void Expect<T>(Action action) where T : Exception
206추가: {
207추가: try
208추가: {
209추가: action();
210추가: }
211추가: catch (T)
212추가: {
213추가: return;
214추가: }
215추가: throw new Exception($"예상 예외 없음: {typeof(T).Name}");
216추가: }
217추가:
218추가: private static void Check(bool condition)
219추가: {
220추가: if (!condition)
221추가: {
222추가: throw new Exception("검사 실패");
223추가: }
224추가: }
225추가:
226추가: private static void Run(string name, Action action)
227추가: {
228추가: try
229추가: {
230추가: action();
231추가: passed++;
232추가: Console.WriteLine($"PASS integration.{name}");
233추가: }
234추가: catch (Exception error)
235추가: {
236추가: failed++;
237추가: Console.WriteLine($"FAIL integration.{name}: {error.GetType().Name}: {error.Message}");
238추가: }
239추가: }
240추가: }
추가tests/gzip-history-integration-probe/PendingValidation.cs+63-0
@@ -0,0 +1,63 @@
1추가: using Zipelo.GzipBoundaryProbe;
2추가:
3추가: // 검증과 정리 이후에만 시험 결과를 확정함. 파일 게시를 구현하지 않음.
4추가: internal sealed class PendingValidation
5추가: {
6추가: private bool used;
7추가: public int CommitCount { get; private set; }
8추가: public string? CommittedHash { get; private set; }
9추가: public BoundaryResult? CommittedBoundary { get; private set; }
10추가:
11추가: public void Execute(ReadOnlyMemory<byte> input, ProbeBudget budget, bool selected,
12추가: CancellationToken token = default, int feedSize = ProbeBudget.ChunkSize,
13추가: Action? afterChunk = null, Action? beforeCommit = null, IRawInflater? inflater = null,
14추가: Action? onSinkDispose = null)
15추가: {
16추가: if (used)
17추가: {
18추가: throw new InvalidOperationException("실패 여부와 관계없이 시험 인스턴스를 재사용하지 않음");
19추가: }
20추가: used = true;
21추가: BoundaryResult result;
22추가: string? pendingHash = null;
23추가: using (var sink = new TemporarySink(onSinkDispose))
24추가: {
25추가: result = BoundaryProbe.Read(input, budget, selected, bytes =>
26추가: {
27추가: if (!selected)
28추가: {
29추가: throw new InvalidOperationException("비선택 출력이 전달됨");
30추가: }
31추가: sink.Append(bytes);
32추가: afterChunk?.Invoke();
33추가: }, token, feedSize, inflater);
34추가: budget.Check(token);
35추가: if (selected)
36추가: {
37추가: sink.Complete(result);
38추가: pendingHash = sink.CommittedHash;
39추가: }
40추가: }
41추가: beforeCommit?.Invoke();
42추가: budget.Check(token);
43추가: CommittedBoundary = result;
44추가: CommittedHash = pendingHash;
45추가: CommitCount = 1;
46추가: }
47추가:
48추가: // 실제 해시 자원을 정리한 뒤 Dispose 내부에서 시험 오류를 주입함.
49추가: private sealed class TemporarySink(Action? onDispose) : IDisposable
50추가: {
51추가: private readonly HashSink inner = new();
52추가: public string? CommittedHash => inner.CommittedHash;
53추가: public void Append(ReadOnlyMemory<byte> bytes) => inner.Append(bytes);
54추가: public void Complete(BoundaryResult result) => inner.Complete(result);
55추가:
56추가: public void Dispose()
57추가: {
58추가: inner.Dispose();
59추가: onDispose?.Invoke();
60추가: }
61추가: }
62추가:
63추가: }
추가tests/gzip-history-integration-probe/contract.json+184-0
@@ -0,0 +1,184 @@
1추가: {
2추가: "schemaVersion": 1,
3추가: "status": "source-prepared; candidate compilation and execution pending central validation",
4추가: "scope": "stage 1: test-only strict single-member GZip boundary parser with history-validating inflater",
5추가: "baseline": {
6추가: "pr": 15,
7추가: "head": "174d9d87d90ed973d9baa06ca1d8de401eba591b",
8추가: "project": "tests/gzip-boundary-probe/Zipelo.GzipBoundaryProbe.csproj",
9추가: "historicalCentralResult": {
10추가: "platforms": [
11추가: "Windows",
12추가: "Ubuntu 26"
13추가: ],
14추가: "passed": 183,
15추가: "failed": 1,
16추가: "exit": 1,
17추가: "failure": "deflate.invalid-backreference-history"
18추가: },
19추가: "rerunThisCandidateBranch": "See historicalCentralResults for the exact tested head. New source head is not executed."
20추가: },
21추가: "candidate": {
22추가: "project": "tests/gzip-history-integration-probe/Zipelo.GzipHistoryIntegrationProbe.csproj",
23추가: "assembly": "Zipelo.Experimental.GzipHistoryIntegrationProbe",
24추가: "inheritedRegressionCases": 184,
25추가: "additionalGroupedCases": 162,
26추가: "expectedExit": 0,
27추가: "actualResult": null,
28추가: "invalidArgumentsExit": 2,
29추가: "outputSections": [
30추가: "candidate.inherited-suite.begin",
31추가: "candidate.inherited-suite.exit",
32추가: "candidate.integration"
33추가: ],
34추가: "note": "expected counts are source enumeration, not observed results; grouped tests include multiple controls and all optional-header prefixes"
35추가: },
36추가: "binding": {
37추가: "historyProject": "tests/deflate-history-validation-probe/Zipelo.HistoryProbe.csproj",
38추가: "historyAlias": "history",
39추가: "types": [
40추가: "Inflater",
41추가: "SharpZipBaseException"
42추가: ],
43추가: "crc": "official SharpZipLib [1.4.2] global reference",
44추가: "sourceChanges": "Candidate BoundaryProbe.cs is a documented copy of the fixed PR15 parser with only failure-path output accounting changes. Program.cs remains linked unchanged. Global aliases bind both parser adapter and exception catch to history assembly.",
45추가: "guard": "assembly.identity checks parser private field type and both assembly identities",
46추가: "separation": "baseline executable uses official package; candidate links original parser and regression sources, references history executable as an assembly without running its entry point"
47추가: },
48추가: "transaction": {
49추가: "helper": "PendingValidation",
50추가: "finalization": "Only after Read completes header, raw finish/counters, CRC/ISIZE and EOF, pending SHA is computed, hash sink is disposed, optional test hook runs, and shared budget/cancellation is checked. Boundary and optional hash are then committed once.",
51추가: "failure": "exception propagates; no committed boundary/hash; one-use wrapper cannot retry; local default inflater is abandoned, no reset/reuse",
52추가: "selectedFalse": "full parse/decode/CRC/ISIZE/budget/EOF checks; no sink output, no selected hash; successful boundary only",
53추가: "publication": "no filesystem output, temp archive, rename, ValidatedArchive, or product file publication is implemented",
54추가: "rollback": "no inflater rollback claim; only final result withholding",
55추가: "disposeSeam": "Optional onSinkDispose action executes inside TemporarySink.Dispose after disposing the original HashSink. This injects an actual wrapper Dispose exception, not a beforeCommit exception; it does not induce a failure in the BCL IncrementalHash implementation. Null hook preserves the existing operation order.",
56추가: "errorPrecedence": "Current C# using semantics: a throwing Dispose replaces an active body Budget/cancellation exception and prevents beforeCommit/final Check. If Dispose succeeds, an active body exception propagates. If both cancellation and deadline become pending inside successful Dispose, final Check reports cancellation. No exception aggregation or new recovery behavior is introduced."
57추가: },
58추가: "budgets": {
59추가: "chunkSize": 65536,
60추가: "accounting": "Input high-water/read-ahead accounting is unchanged. Every Inflate call records its observable TotalOut delta in finally before exception propagation or post-call cancellation/time checks. Successful output is not charged twice. Selected output is charged only on the existing sink delivery path. Repeated attempts share the same budget without reset/refund.",
61추가: "time": "same start and TimeProvider through parse, hashing, disposal and final check; cooperative checks cannot interrupt synchronous decoder call",
62추가: "externalLimitSecondsPerProcess": 60,
63추가: "failedOutput": "TotalOut measures bytes copied into the caller output buffer, including bytes copied by a call that subsequently throws. It does not expose bytes still held only inside OutputWindow. No decoder internals are modified.",
64추가: "overLimit": "Record actual bounded output delta even when it exceeds ProcessedLimit; then throw Budget. Processed may exceed the configured limit by at most 65536 and remains recorded. Check rejects later attempts. A valid delta that exceeds the budget takes precedence over an Inflate exception; invalid negative/oversized delta produces Boundary. Otherwise preserve Deflate/cancellation/original exception.",
65추가: "invalidCounter": "Negative or >65536 TotalOut delta is Boundary in finally before ChargeDecoded or post-call Check, including when cancellation/deadline is pending. Invalid deltas are not charged or trusted. Existing valid-delta over-limit Budget precedence is unchanged."
66추가: },
67추가: "coverage": [
68추가: "all original baseline negative expectations unchanged",
69추가: "matching CRC/ISIZE invalid history versus valid zero and static empty controls",
70추가: "selected true/false and feed 1/2/3/7/65536",
71추가: "header options/FHCRC, CRC/ISIZE, truncation and trailing/single-member policies",
72추가: "consumed/remaining, read-ahead and exact trailer position, output counters",
73추가: "input/processed/output/metadata limits and cancellation inherited unchanged",
74추가: "new final cancellation/deadline after sink disposal, same-budget repeated attempts, input immutability, fresh inflater after rejection",
75추가: "10 additional groups: selected true/false actual stored-A then reserved-block failure, over-limit failure, return-time cancellation/deadline/other exception; verify retained TotalOut cost, no sink output or committed result, and same-budget retry refusal before another Inflate call",
76추가: "26 new groups: 10 Dispose groups (5 scenarios x selected false/true, each with nonthrowing control and throwing wrapper); 16 invalid TotalOut groups (delta -1/65537 x no overlap/cancellation/deadline/both x selected false/true). Assert no public committed boundary/hash/count on failure, actual disposal, final-hook reachability, retained input accounting, and competing Check outcome. No decoder or baseline edits."
77추가: ],
78추가: "exclusions": [
79추가: "product adoption or main merge",
80추가: "GZip filesystem publication or production integration",
81추가: "stage 2 general dynamic trees, upper zlib dictionary/Reset integration, new partial-drain matrix",
82추가: "stage 3 performance measurement",
83추가: "complete decoder/security certification"
84추가: ],
85추가: "execution": {
86추가: "environment": "central isolated workspace using existing verified SDK 10.0.403/runtime 10.0.14; do not install SDK or download packages",
87추가: "sourceVerification": "From repository root, sha256sum -c tests/gzip-history-integration-probe/SHA256SUMS; compare full file inventory in provenance.json. Check again after execution.",
88추가: "restore": "dotnet restore <project> --configfile tests/gzip-history-integration-probe/NuGet.Config --source <existing-verified-offline-feed> --packages <isolated-packages-path> -p:NuGetAudit=false",
89추가: "restoreChecks": "Only official SharpZipLib 1.4.2 net6.0 asset; no network sources/fallback; verify existing approved nupkg SHA before use. History project has zero PackageReference. Baseline and candidate each restored separately.",
90추가: "build": "dotnet build <project> --no-restore -c Release -p:NuGetAudit=false",
91추가: "runBaseline": "dotnet tests/gzip-boundary-probe/bin/Release/net10.0/Zipelo.GzipBoundaryProbe.dll",
92추가: "runCandidate": "dotnet tests/gzip-history-integration-probe/bin/Release/net10.0/Zipelo.Experimental.GzipHistoryIntegrationProbe.dll",
93추가: "invalidCli": "Run both DLLs with --invalid; expect exit 2.",
94추가: "warnings": "Candidate authored sources treat warnings as errors. Referenced unchanged history project preserves its own warning policy and original SYSLIB0051 warning; do not pass a global warnings-as-errors override or suppress it.",
95추가: "results": "Record exact head, SDK/runtime, restore/build exits and warnings, separately baseline/candidate counts and invalid CLI exits on Windows/Linux, package/source/DLL hashes before/after and no residual processes. Do not upload logs, binaries or generated corpus.",
96추가: "constraints": "Apply 60-second external process bound and isolated output/package locations. No restore/build/run was performed by author."
97추가: },
98추가: "regressionFixtures": [
99추가: {
100추가: "rawHex": "00 01 00 FE FF 41 07",
101추가: "basis": "non-final stored block, LEN=1 and NLEN=65534, literal 0x41, then final reserved BTYPE=3; malformed independently of trailer",
102추가: "expected": "Deflate with one observed TotalOut byte retained when budget sufficient; Budget with usage retained when one byte over limit"
103추가: },
104추가: {
105추가: "rawHex": "01 01 00 FE FF 41",
106추가: "basis": "final stored block with one literal A; valid",
107추가: "expected": "one copied output byte; injected post-return cancellation/deadline/IOException must retain cost without publishing"
108추가: }
109추가: ],
110추가: "priorCandidate": {
111추가: "head": "4ada9f9e8c693288127792c925bc88a5ebc4a9fe",
112추가: "status": "unexecuted candidate with failure-path output accounting omission identified by static review; not a validated baseline"
113추가: },
114추가: "historicalCentralResults": [
115추가: {
116추가: "head": "2d2ef7f472673d386fed2ef7fe98cc7522ef56f6",
117추가: "source": "coordinator-reported central execution; not rerun by author",
118추가: "buildHost": "Windows",
119추가: "sdk": "10.0.403",
120추가: "runtime": "10.0.14",
121추가: "platforms": [
122추가: "Windows build 26300",
123추가: "Ubuntu 26.04.1"
124추가: ],
125추가: "restoreExit": {
126추가: "baseline": 0,
127추가: "candidate": 0
128추가: },
129추가: "buildExit": {
130추가: "baseline": 0,
131추가: "candidate": 0
132추가: },
133추가: "candidateWarnings": [
134추가: "one original SharpZipBaseException.cs SYSLIB0051"
135추가: ],
136추가: "errors": 0,
137추가: "perPlatform": {
138추가: "baseline": {
139추가: "passed": 183,
140추가: "failed": 1,
141추가: "exit": 1,
142추가: "onlyFailure": "deflate.invalid-backreference-history"
143추가: },
144추가: "candidate": {
145추가: "inheritedPassed": 184,
146추가: "inheritedTotal": 184,
147추가: "additionalPassed": 136,
148추가: "additionalTotal": 136,
149추가: "exit": 0
150추가: },
151추가: "invalidCliExit": {
152추가: "baseline": 2,
153추가: "candidate": 2
154추가: }
155추가: },
156추가: "samePortableAssembly": true,
157추가: "externalSecondsPerProcess": 60,
158추가: "timeouts": 0,
159추가: "residualProcesses": 0,
160추가: "unchangedHashes": {
161추가: "sourceFiles": 41,
162추가: "dllCopies": 6,
163추가: "offlineNupkg": true
164추가: },
165추가: "candidateDllSha256": "cb2c7821f4c68b5b54acca8827a9e42e39c0932b0edd9d364a62148a7a53fe5f",
166추가: "limits": "Finite synthetic cases only. Does not validate subsequent heads, file publication, general decoder safety, stages 2/3 or product adoption."
167추가: }
168추가: ],
169추가: "finalizationRegression": {
170추가: "file": "FinalizationRegression.cs",
171추가: "addedGroupedCases": 26,
172추가: "disposeScenarios": [
173추가: "successful parse",
174추가: "body deadline Budget",
175추가: "body cancellation",
176추가: "body deadline and cancellation",
177추가: "deadline and cancellation inside Dispose"
178추가: ],
179추가: "disposeAssertions": "Same injected IOException instance, exactly one Dispose, beforeCommit never reached when disposal throws, no public committed boundary/hash and count zero. Nonthrowing controls prove success or original failure priority. Both selected paths allocate/dispose the sink, but selected=false neither appends nor completes a hash.",
180추가: "counterFixture": "Valid stored-A raw 01 01 00 FE FF 41, actual patched inflater output 1. Adapter changes only observed TotalOut after return to -1 or 65537. This is a contract-violation mock, not malformed Deflate input.",
181추가: "counterAssertions": "Boundary before final Check, one Inflate, actual output 1 but output delivery 0, processed input only, Dispose once, beforeCommit zero, committed boundary/hash absent and count zero. Separate Check demonstrates pending cancellation/Budget condition.",
182추가: "execution": "Source enumeration only; new head compilation and execution pending central validation."
183추가: }
184추가: }
수정tests/rust-integration-baseline/SHA256SUMS+2-2
@@ -1,2 +1,2 @@
1삭제: b107f066376b147df0609d179b500fc1a35b445fbf059d7ed4afcb823e5647d0 run-plan.json
2삭제: 276d0c79976c1f226e4230fe07a21b9f7af065fc54713457360442cf25316289 sources.json
1추가: 0432d5e8d8e75867bcbdde3d66b468f9c66455c211925f3ea2a9a7f71ba33d30 run-plan.json
2추가: d28874ea921a8027029f37bf35b64cb804c8e19345be893bc37a929d8b9dd932 sources.json
수정tests/rust-integration-baseline/run-plan.json+10-4
@@ -1,15 +1,15 @@
11{
22 "schema": 1,
3삭제: "state": "검토 대기. 후보 tree에서 compile/discovery/runtime을 실행하지 않음",
3추가: "state": "7개 고정 baseline 비교 입력 보완 후 검토 대기. static/metadata/compile/discovery/runtime 재실행 없음",
44 "branch": "features/rust-integration-baseline",
55 "steps": [
66 {
77 "stage": "identity",
8삭제: "required": "고정 candidate commit/tree 및 sources.json의 295개 path/mode/type/blob와 SHA256SUMS 검증. main 144개 전부 일치해야 함. 최초 차이에서 중단"
8추가: "required": "고정 candidate commit/tree 및 sources.json의 302개 path/mode/type/blob와 SHA256SUMS 검증. main 144개 전부 일치해야 함. 최초 차이에서 중단 7개 baseline은 byte 비교만 하며 C# 컴파일/실행 대상에서 제외함."
99 },
1010 {
1111 "stage": "static",
12삭제: "required": "새 격리 검증 checkout에서 원본 static_check.py와 dependency audit, rustfmt --check 및 명시적 기존 toolchain의 cargo metadata --locked --offline. source/lock/fixture 변경 금지. 설치/restore 없음"
12추가: "required": "새 격리 검증 checkout에서 원본 static_check.py와 dependency audit, rustfmt --check 및 명시적 기존 toolchain의 cargo metadata --locked --offline. source/lock/fixture 변경 금지. 설치/restore 없음 dependency_audit.py는 dependencies.json을 쓰므로 승인 후 별도 폐기 가능한 검증 사본에서만 수행하고 고정 원본과 비교함. 변경된 출력으로 고정 입력을 덮지 않음."
1313 },
1414 {
1515 "stage": "headless",
@@ -92,5 +92,11 @@
9292 "Windows/Ubuntu24/실제 사용자 display/IME/전체 접근성 미검증",
9393 "기존 16실패/7미검증 및 execveat EACCES 보류를 유지함",
9494 "main merge 없음"
95삭제: ]
95추가: ],
96추가: "first_failure_preserved": {
97추가: "path": "tests/rust-integration-baseline/validation-e015332b-independent/result-audit.json",
98추가: "sha256": "4a5d380ccbe3f4bc09dc2e515b98cd9f93ac5a7915e86d6ead4fa1d6c3434269",
99추가: "preserved": true
100추가: },
101추가: "reference_audit": "sources.json/reference_audit"
96102}
수정tests/rust-integration-baseline/sources.json

Diff가 표시 한도를 넘어서 생략했어요.

Raw로 열기