Repository navigation
test: assert the encrypt-dictionary fixture is huge, and widen its pin - #456
Merged
Merged
Conversation
Tim81
force-pushed
the
fix/400-scaling-pin
branch
from
September 9, 2026 06:40
8371c00 to
a3eb927
Compare
Tim81
force-pushed
the
fix/400-scaling-pin
branch
5 times, most recently
from
September 9, 2026 08:53
695163d to
ae01382
Compare
EncryptDictionaryDenialOfServiceTests opened an /Encrypt dictionary with 100,000 filler keys under a ten-second budget, as the #208 regression pin. It was cancelled at that budget three times on GitHub's shared runner, on branches touching neither the reader nor the test, most recently one whose entire diff was a workflow file and a CHANGELOG entry. A time budget only pins a regression if the pre-fix cost exceeds it on the slowest machine the suite runs on, and ten seconds against a third of a second was not the margin it looked like. #400 records that assembly at 6m 21s on the runner against 34s here, and it runs its classes in parallel with the CsCheck fuzzer, which takes every core. #400 now also records contention between concurrent sessions on a developer machine, which nobody sized the budget against either. #400 rejected simply raising the budget, correctly, because that weakens the pin. Raising the key count instead widens the gap the budget sits in: the cost this guards against grows with the square of the count while the fixed cost grows with the count itself. Measured in Release on the development machine with PdfDictionary's index disabled: 538 ms at 12,500 keys, 1.6 s at 25,000, 6.7 s at 50,000, 34 s at 100,000, 126 s at 200,000, each doubling costing between 2.9 and 5.1 times as much. Carried out one more doubling, 400,000 keys lands near eight minutes broken, against about a quarter of a second fixed. The eight minutes is extrapolated, not measured: the only direct observation at 400,000 broken is this test being cancelled at its budget, which is a floor and no ceiling. What the two-minute budget buys, measured. Run alone the whole test takes about half a second, and inside its own assembly about two, so it uses at most a couple of per cent of the budget. Under deliberate saturation — the full assembly plus 256 busy loops on sixteen cores, which slowed the assembly 13.7x and broke five other tests — it took 37.7 s and passed. Failing it needs about 240 times the alone cost, or 60 times the in-assembly cost; the budget it replaces failed at about 30 times its own alone cost. Verified in both directions: with IndexThreshold set to int.MaxValue it fails, cancelled at 120.2 s. Only the passing margin improves, and that is the one #400 is about. The failing margin barely moves: the pre-fix cost overran the old ten-second budget about three and a half times at 100,000 keys, and on the extrapolation above overruns this one about four times at 400,000. Two designs were rejected getting here, and both failed the same way. The first compared timings at two key counts and asserted a ratio, on the reasoning that contention affects both and divides out; under load the benign ratio reached 24.6 against 26.1 for the real defect. The second was a passing margin computed by scaling this test's local time by an assembly-level slowdown; under a lighter run, 64 busy loops rather than 256, the assembly slowed 2.4x while this one test slowed 11x, because a single CPU-bound region absorbs preemption far worse than an average over many. A slowdown factor does not transfer between measurements at different scales. Six other tests use an absolute budget the same way, one of them, ManyStreamsWithNoEolBeforeTheirOwnEndstream_DoesNotBecomeQuadratic, in this same assembly and therefore sharing a process with the fuzzer. That one measures 13 ms against ten seconds in Release, more relative headroom than the new pin. The other five have not been measured. All are left for the sweep #400 asks for. Refs #400, #208.
Successive edits to this test's class doc and its CHANGELOG entry spliced new clauses into existing lines and left three one- and two-word lines mid sentence. Both blocks are rewrapped to the width the rest of each file uses, 102 columns in the test and 100 in the CHANGELOG. One wrap needed a reworded lead-in. The runner's status string is written as inline code, and at the old wrap point Markdown would have split the span across two lines, which renders the backticks literally. No wording changes, no change to the key count, the budget, or any assertion. Refs #400.
Review round four. One test change, the rest is the class doc and the CHANGELOG saying what was actually measured. The test asserted only that the open produced user-level encryption, so it could not tell a working fix from a fixture that had quietly stopped being huge. PdfObjectParser caps nesting depth and nothing else today, but an entry cap is exactly the hardening this neighbourhood attracts, and the day one lands at a few thousand entries the open returns fast, both assertions still hold, and the pin silently stops pinning. It now checks the last filler key is in the bytes it opens. The CHANGELOG said only the Reader assembly's budget shares a process with a CsCheck fuzzer. All six do. Microsoft.Testing.Platform gives each test project its own process, and VellumPdf.Kernel.Tests references CsCheck and samples generators in PropertyTests at the default iteration count. That matters because it pointed the #400 sweep away from the two budgets in PdfDictionaryIndexTests, which are the other half of this same #208 pin and were sized by the same local reasoning #400 disproved. The class doc claimed this test would catch a fix that left DereferenceValues quadratic. DereferenceValues builds its copy entirely through PdfDictionary.Set and holds no collection of its own, so there is nothing there to leave quadratic. What this pins is the write path; the read path is pinned by ShallowCopy_pastTheThreshold_carriesTheIndex, and the #208 pin is complete only as that pair. Three figures are now checkable that were not. The 11x slowdown is stated against its alone cost, with the heavier run given the same way, 13.7x against 75x, so the two runs can be compared. The projection factor is named: the series fits an exponent of 1.97, so the next doubling was taken at 4x rather than anywhere in the published 2.9 to 5.1 band. The two fixed costs, a quarter second and half a second, are distinguished as open cost and whole test. Also: #400 was opened on two cancellations, not three, and the third arrived a week later; #400's own two-to-three-times overrun is superseded by the 3.4 remeasured here; the saturation figure of 37.7 s is 31% of the budget, which is the smallest margin any measurement produced and is now stated as such; and every margin here is from this machine, not from the runner that flaked. The filler builder reserved ten characters per key where a key costs nineteen, and built the document through two more full-length copies. Refs #400, #208.
The comment said the fixture assertion stops the pin from silently ceasing to pin when a parser entry cap arrives. It does not. It reads the bytes before the open, so a reader that discards entries leaves those bytes untouched and the assertion still passes. The assertion is worth keeping, because it catches a mis-edit of the builder, which is what the CHANGELOG already said it caught. Catching the other case needs an assertion on what the open produced, and the /Encrypt dictionary is not reachable from the test. The CHANGELOG had ParserFuzzTests as the lighter of the two CsCheck users, because it caps itself through FuzzBudget. Backwards: FuzzBudget's default is 3,000 iterations against CsCheck's own default of 100, which is what PropertyTests runs at, and five more classes in the Reader assembly sample at the same budget. So this assembly is the heavier side, not the lighter one. The claim had also gone out in the PR body and in a comment on #400; both are corrected. Two figures. The exponent was described as a fit over the series when 1.97 is what the endpoints give; a least-squares fit over all five points gives 2.02, and both are now stated. The CHANGELOG kept the unqualified "a quarter of a second fixed" that the class doc had already split into open cost against the half second the whole test takes. Reader suite 1869 total, 0 failed, 12 skipped, the skips pre-existing and fixture-based. Refs #400.
Tim81
force-pushed
the
fix/400-scaling-pin
branch
from
September 9, 2026 10:44
9c04dc9 to
f12a4cc
Compare
Tim81
added a commit
that referenced
this pull request
Nov 18, 2026
A Stopwatch checked after a call returns cannot end a hang, and a 10 s bound fails on a loaded runner: the main CI run for 1c61fa6 failed FindingHigh_A4FlateBombPadding_refusesQuickly_viaCostBudget at 11.79 s, and #400 records two 10 s Timeout cancellations of the #208 encrypt-dictionary pin. Most sites now pin something the code decides, or a bound on bytes allocated on the calling thread. PageTreeTests' deep malformed-ancestor walk drops its clock without a replacement, because a quiet per-leaf rescan changes nothing a test can observe without a src hook. PdfDictionary gains an internal IsIndexed. The #208 tests assert that the index exists and that ShallowCopy carries it, and an entry-swap check shows that TryGet follows the index and does not scan. The parser, reader and content-interpreter fuzz targets check per-sample allocation ceilings; the lexer target keeps its token-count bound. The Layout cap-test renderers stop themselves after 200,004 Layout calls, so their Timeout can be a 300 s hang guard. The one Timeout kept as a regression pin is the 120 s guard on the /Encrypt dictionary test, sized and measured in #456.
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.
Replaces a wall-clock regression pin that its own budget kept cancelling. Refs #400: this is the reader-side test only, and the sweep #400 asks for is still open.
The problem
EncryptDictionaryDenialOfServiceTestsopened an/Encryptdictionary carrying 100,000 filler keys under a ten-second budget, as the #208 regression pin. It has been cancelled at that budget three times on GitHub's shared runner, on branches touching neither the reader nor the test. #400 was opened on the first two; the third arrived a week later, on PR #446, whose entire diff is a workflow file and a CHANGELOG entry.A time budget only pins a regression if the pre-fix cost exceeds it on the slowest machine the suite runs on, and ten seconds against a third of a second was not the margin it looked like. #400 records the Reader assembly at 6m 21s on the runner against 34s here, and it runs its classes in parallel with the CsCheck fuzzer, which takes every core. #400 now also records contention between concurrent sessions on a developer machine, which nobody sized the budget against either.
What this does
It is still a wall clock. What changes is the problem size, not the mechanism.
#400 rejected simply raising the budget, correctly, because that weakens the pin. Raising the key count instead widens the gap the budget sits in, since the guarded cost grows with the square of the count while the fixed cost grows with the count itself. The test now opens 400,000 keys once, under a two-minute budget.
Measured in Release on the development machine, with
PdfDictionary's index disabled by raisingIndexThresholdtoint.MaxValue: 538 ms at 12,500 keys, 1.6 s at 25,000, 6.7 s at 50,000, 34 s at 100,000, 126 s at 200,000 — each doubling costing between 2.9 and 5.1 times as much. The endpoints imply an exponent of 1.97 and a least-squares fit over all five points gives 2.02, so the next doubling was projected at the quadratic's 4x rather than anywhere in that band: 400,000 keys lands near eight minutes broken, against about a quarter of a second of open cost fixed. That is not the same measurement as the half second the whole test takes with the fixture built.The eight minutes is extrapolated, not measured. What was measured is the direction: with
IndexThresholdraised the test does fail, cancelled at 120.2 s, which puts a floor under the broken cost and no ceiling.The test also now asserts the last filler key is present in the bytes it opens. Without that it could not tell a working fix from a fixture a mis-edit had quietly stopped making huge. It checks the bytes rather than the parsed document, so it would not catch a reader that later starts discarding entries; that needs an assertion on what the open produced, and the
/Encryptdictionary is not reachable from the test.What the budget buys
Every figure below is from the development machine, not from the runner that flaked, and #400 exists because a local figure mispredicted the runner once already.
Run alone the whole test takes about half a second, and inside its own assembly about two. Unloaded that is a couple of per cent of the budget. Under deliberate saturation — the full assembly plus 256 busy loops on sixteen cores, which slowed the assembly 13.7x and broke five other tests — it took 37.7 s and passed. That is 31% of the budget and the smallest margin any measurement here produced.
Failing it unloaded needs about 240 times the alone cost, or 60 times the in-assembly cost. The budget it replaces failed at about 30 times its own alone cost.
Only the passing margin improves, and that is the one #400 is about. The failing margin barely moves: the pre-fix cost overran the old ten-second budget about three and a half times at 100,000 keys, and on the extrapolation above overruns this one about four times at 400,000. #400's body puts that first overrun at two to three times; the 3.4 here is a remeasurement and supersedes it.
Two rejected designs, both failing the same way
The first compared timings at two key counts and asserted a ratio, on the reasoning that contention affects both and divides out. Under load the benign ratio reached 24.6 against 26.1 for the real defect, because taking the fastest of several samples drags a short measurement to its floor while a long one absorbs every preemption.
The second was a passing margin computed by scaling this test's local time by an assembly-level slowdown. Under a lighter run, 64 busy loops rather than 256, the assembly slowed 2.4x while this one test slowed 11x off its alone cost, and the heavier run says the same on those same baselines, 13.7x against 75x. A slowdown factor does not transfer between measurements at different scales.
Scope
Six other tests use an absolute
Timeoutthe same way, and all six share a process with a CsCheck fuzzer, not only the one in this assembly: Microsoft.Testing.Platform gives each test project its own process, and the five inVellumPdf.Kernel.Testssit alongsidePropertyTests, which samples generators at CsCheck's default iteration count.ParserFuzzTestshere is the heavier of the two:FuzzBudget.DefaultIterationsis 3,000 against CsCheck's default of 100, and five more classes in this assembly sample at the same budget.Only
ManyStreamsWithNoEolBeforeTheirOwnEndstream_DoesNotBecomeQuadraticwas measured, at 13 ms against ten seconds in Release, more relative headroom than the new pin. Two of the unmeasured five, inPdfDictionaryIndexTests, are the other half of the #208 pin and are sized by the same local reasoning #400 disproved, so they are where the sweep should start. That sweep is wider than these six, since #400 greps forStopwatchandTimeSpan.FromSecondstoo.Test-only; nothing ships.