portTemplate.count has no upper bound (1000000 or Infinity kills the boot), and the engine keeps a second copy of the expansion rule #1319

Closed
opened 2026-11-10 02:27:05 +00:00 by jaylouisw · 0 comments
Owner

Two findings in the same corner. The second one is a boot-time denial of service.

1. Two copies of the expansion rule, and the test between them could not see the difference

devices/registry.js and engine/topology.js each had an expandInterfaces. The test that was supposed to keep
them in step compared port names over the catalogue — so a divergence in any other field, on any spec outside
the catalogue, or in any edge case, was invisible by construction.

I measured it: over all 2,015 specs the copies agree on every field of every port today, and on every synthetic
edge case I could build. So the drift had not happened yet. But they had already diverged where it counts:

devices/registry.js    count: 1000000  ->  refused as a broken spec
engine/topology.js     count: 1000000  ->  built a million ports

engine/topology.js carries the comment "the cleanest end state is for engine/topology.js to call this function
instead of keeping its own copy ... so for now the two are kept in step by that test"
. The test does not keep them
in step; nothing can.

2. count has a documented ceiling that nothing enforced

docs/DEVICE_SCHEMA.md:

count is 1..512, prefix must be non-empty, and the expansion must produce at least one port.

The loader's gate was typeof count === 'number' && Math.floor(count) === count && count > 0. So:

  • count: 1000000 passes — one number in one file, and the loader builds a million ports at boot;
  • count: Infinity passes too, because Math.floor(Infinity) === Infinity and Infinity > 0. Expanding it never
    returns. Measured against the current code, with the two files reverted:
node test/port-count.test.js
exit=134                      (allocation failure - the process died building the list)
2 of 15 checks reported

That is a single spec file, or a hand-edited saved board (/load never passes through the loader), taking the
process down before it serves anything.

What must be true instead

  • one implementation of "a spec's ports", called by the engine rather than copied — the end state that file has
    described since #71;
  • a count that is not a whole number in 1..512 is refused with the range in the message, by the loader (naming
    the file) and by the expander (for the doors the loader does not guard, such as a saved board);
  • an absent count still means one port, 512 is still allowed, and the whole catalogue still loads;
  • Infinity is reported as Infinity, not as null (which is what JSON.stringify gives).
Two findings in the same corner. The second one is a boot-time denial of service. ## 1. Two copies of the expansion rule, and the test between them could not see the difference `devices/registry.js` and `engine/topology.js` each had an `expandInterfaces`. The test that was supposed to keep them in step compared **port names over the catalogue** — so a divergence in any other field, on any spec outside the catalogue, or in any edge case, was invisible by construction. I measured it: over all 2,015 specs the copies agree on **every field of every port** today, and on every synthetic edge case I could build. So the drift had not happened yet. But they had already diverged where it counts: ``` devices/registry.js count: 1000000 -> refused as a broken spec engine/topology.js count: 1000000 -> built a million ports ``` `engine/topology.js` carries the comment *"the cleanest end state is for engine/topology.js to call this function instead of keeping its own copy ... so for now the two are kept in step by that test"*. The test does not keep them in step; nothing can. ## 2. `count` has a documented ceiling that nothing enforced `docs/DEVICE_SCHEMA.md`: > `count` is **1..512**, `prefix` must be non-empty, and the expansion must produce at least one port. The loader's gate was `typeof count === 'number' && Math.floor(count) === count && count > 0`. So: * `count: 1000000` passes — one number in one file, and the loader builds a million ports at boot; * `count: Infinity` passes too, because `Math.floor(Infinity) === Infinity` and `Infinity > 0`. Expanding it never returns. Measured against the current code, with the two files reverted: ``` node test/port-count.test.js exit=134 (allocation failure - the process died building the list) 2 of 15 checks reported ``` That is a single spec file, or a hand-edited saved board (`/load` never passes through the loader), taking the process down before it serves anything. ## What must be true instead * one implementation of "a spec's ports", called by the engine rather than copied — the end state that file has described since #71; * a count that is not a whole number in 1..512 is **refused** with the range in the message, by the loader (naming the file) and by the expander (for the doors the loader does not guard, such as a saved board); * an absent count still means one port, 512 is still allowed, and the whole catalogue still loads; * `Infinity` is reported as `Infinity`, not as `null` (which is what `JSON.stringify` gives).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge#1319
No description provided.