Repository navigation
test: replace wall-clock cost assertions with deterministic pins - #577
Merged
Merged
Conversation
The 10 s Timeout attributes on the cmap, PNG and PdfDictionary pins could not tell the defect from a slow runner: a Timeout is a hang guard, and the broken work in the cmap and PNG cases is milliseconds. They also failed on loaded CI for the wrong reason (#400). PdfDictionary gains an internal IsIndexed so the #208 tests assert that the index was built and that ShallowCopy carries it, 100 keys in, instead of timing a quadratic 140,000-key build. The PNG zlib-bomb tests bound the bytes allocated on the calling thread (91,224 measured; 10.5 MB when the cap is checked after the loop) and read the cap's message. The cmap test reads its budget message. Remaining Timeouts and the signing WaitAsync calls are 300 s hang guards.
…Timeout The continuation-cap tests ended a runaway only through a 10 s Timeout, which a loaded runner can hit on a render that is merely slow (#400). A longer Timeout alone would let a cap-removed mutation reach OOM with no test name, so the renderers now count Layout calls and fail past 4 x 50,001. With the cap check disabled, the three tests fail by name in 1.4 s at a 155 MiB polled peak (Debug). The Timeout becomes a 300 s hang guard.
Stopwatch checks made after a call returns cannot end a hang and fail on a loaded runner (#400). The A4 flate-bomb test reads the budget's message and bounds per-thread allocation (8 MiB; 2.15 MB measured, 42.1 MB when the charge lands after the loop). The parser test closes with a well-formed stream so a scan that skips EOL-less terminators returns a wrong body. PageTree drops the clock for diagnostic-code checks. The fuzz targets check a per-sample allocation ceiling that scales with input length and keeps CsCheck's seed; they carry no Timeout because the nightly runs 200,000 iterations per case. The #456 Timeout stays, with a comment saying why.
The bound's comment pointed at the PR for its numbers. It now states them: 91,224 bytes with the cap firing, 10.5 million with it checked after the loop.
An index that is built and carried by ShallowCopy but never consulted passed every #208 test in under a second. The tests now swap two backing entries behind the index's back and require TryGet to follow the index, on the source and on the copy. IsIndexed's doc now says what builds the index and that it does not show TryGet consults it. The PNG bound drops from 1 MiB to 256 KiB: a cap that fires 245,000 bytes late (337,032 allocated) now fails.
The fuzz Facts get 300 s hang guards: the nightly ran all five ParserFuzz tests at 200,000 iterations in 15 s, so the earlier claim that a fixed limit would cancel it was wrong. The A4 bound drops from 8 MiB to 5 MiB, so a reconstruction that refuses after three decodes (6.4 million allocated) now fails. Comments gain dates and configurations, the '[' reconstruction allocation is recorded as an uncovered shape, and a stale reference to a removed ten-second budget is gone.
The '[' comment now states a run of 192 built by eight operations and the measured failure (4,429,360 bytes against a 2,666,496-byte ceiling), and the class doc's ratios come from the 1,000,000-sample run. The CHANGELOG no longer implies the lexer target has an allocation ceiling. The EncryptedReconstructionTests clock is cited by its CI run, and the #456 Timeout comment says why nothing deterministic replaces it.
The #208 test said the /Encrypt dictionary was not reachable from the test; it is, through reader.Trailer. The comment now says it is not inspected and why. One ParserFuzzTests doc line is wrapped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #400. Related: #456.
A
Stopwatchchecked after a call returns cannot end a hang, and a 10 s bound fails on a loaded runner: the main CI run for 1c61fa6 failedFindingHigh_A4FlateBombPadding_refusesQuickly_viaCostBudgetat 11.79 s, and #400 records two 10 sTimeoutcancellations of the #208 encrypt-dictionary pin. Most sites now pin something the code decides, or a bound on bytes allocated on the calling thread. All figures below are from local runs on 2026-11-18 unless stated.The only src change is
internal bool IsIndexed => _index is not null;inPdfDictionary. No PublicAPI change.Classification of every hit of the wide grep
git grep -n -E "Stopwatch|Elapsed|TickCount|GetTimestamp|DateTime\.(Utc)?Now|Timeout *=|WaitAsync\(TimeSpan|CancelAfter|time:" -- tests(52 hits at 1c61fa6)MalformedInputTestscmapContains, 300 s guardMalformedInputTestsPNG bomb, interlaced PNG bombPdfDictionaryIndexTestsx2IsIndexed100 keys in and after the build, entry-swap check, 300 s guardIndexThreshold=int.MaxValuefails by name in under 1 s;copy._index = nullfails;TryGetignoring the index fails ("Expected 1, Actual 0") on both tests in 1 s wallSignatureTests700, 704WaitAsync(30 s)-> 300 sEncryptionTests509,PdfDictionaryIndexTests32TestTimestampClient,TimestampTests(GetTimestampToken*)PaginationDepthTestsx3Layoutcalls andAssert.Failpast 200,004ContentInterpreterTestshelperRunallocating 40 MiB fails both FactsEncryptDictionaryDenialOfServiceTestsTimeout = 120_000kept, comment names #456 and #400IndexThreshold=int.MaxValue), not re-runEncryptedReconstructionTestsA4PageTreeTestsshared/KidsarrayDoesNotContainnode-limit and depth-limit codesDoesNotContainfailsPageTreeTestsdeep malformed chainParserFuzzTests(lexer, parser, reader x2)Open+40 MiB fails both reader rows; parser constructor +40 MiB failsPdfObjectParserTestsmany streamsbreakfails; scan on but keep first passes (limit)SaveDecryptedTests, csproj line 26ExternalTooldrain deadline,RemainingMs,IsTimeout, commentAfter this change the only
[Fact(Timeout)]that is a regression pin and not a 300 s hang guard is the #456 test. TheHttpTimestampClient50 ms client timeouts do not match the grep and are untouched.Allocation pins (bytes on the calling thread)
Fuzz ceilings
Each is
1 MiB + K x input length(the 1 MiB isReaderLimits.MinMaxDecodedBytes), K = 128 (parser), 2,048 (reader), 1,024 (content interpreter). K comes from hostile shapes measured at 256 KiB / 1 MiB (17 shapes for parser and reader, 16 for content), at 2.4x (parser), 4.9x (reader) and 5.7x (content interpreter) the worst. Over 1,000,000 samples (Release, 2026-11-18) the reader's worst sample allocated 1,743,608 bytes on a 1,433-byte input, 0.44 of that sample's ceiling, the tightest of the three; the parser's worst allocated 143,184 bytes (0.077 of its ceiling) and the content interpreter's 25,528 (0.012).ParserFuzzTestsatVELLUMPDF_FUZZ_ITER=1000000passed 5/5, taking 28.8 s to 89 s across local runs on 2026-11-18; the two content Facts passed in 23 s. At real sample lengths (up to about 6.5 KB) the 1 MiB slack dominates every ceiling, so all three catch gross regressions only.Stated limits
Discovery, not part of this change
PdfReader.OpenwithAllowReconstruction = trueallocates hundreds of megabytes on a run of[: 26 MB at 512 bytes, 64 MB at 1 KiB, 293 MB at 4 KiB, 304 MB from 8 to 64 KiB and 609 MB at 256 KiB (MaxDecodedStreamBytes1 MiB). A 192-byte run inside a 790-byte file already allocates 4.4 MB. With reconstruction off, about 1 KB. No tracking issue is filed yet. The reader fuzz ceiling cannot admit the long runs; the ceiling comment says so.Verification
Release, one project at a time: Kernel.Tests 1525 passed, 0 skipped; Reader.Tests 1869 passed, 12 skipped; Layout.Tests 412 passed, 31 skipped, also under
DOTNET_TieredCompilation=0.dotnet format --verify-no-changesandeng/clean-room-check.ps1pass.