Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/schema-python-resource-bounds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: schema python resource bounds

# THE PYTHON PORT'S BOUNDED MEMORY/TIME GATE (schema-python-resource-bounds). A
# hostile input (deep nesting, recursion, a huge count, a giant string, many
# unknown fields) must cost bounded memory and time: allocation is bounded by
# input size times the documented factor over tracemalloc, and nesting past
# section 16.9.4's depth cap of 128 is refused by name. Time is asserted by
# executed line events, never wall clock.
#
# THE HEAVY PART IS NIGHTLY ONLY, so the gate stays inside the fast lane's
# one-minute budget: the full bounds sweep runs on the schedule and on
# workflow_dispatch. A dispatch also runs the planted-bad-pattern control,
# which proves the gate has a blade and is seconds of work.
#
# FORK SAFETY: as in the sibling lanes, every fleet job carries the fork guard
# so a fork's pull request never runs on fleet hardware.

on:
schedule:
- cron: '21 3 * * *'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || format('{0}-{1}', github.event_name, github.ref) }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
fast:
runs-on: [self-hosted, linux, x64, fleet]
timeout-minutes: 10
defaults:
run:
shell: go run ./tools/pgroup -- bash -e {0}
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: the pinned Python interpreters
run: make dist-python
- name: planted-bad-pattern control
run: make schema-python-resource-bounds-negative-control
nightly:
runs-on: [self-hosted, linux, x64, fleet]
timeout-minutes: 10
defaults:
run:
shell: go run ./tools/pgroup -- bash -e {0}
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: the pinned Python interpreters
run: make dist-python
- name: bounded memory/time sweep
run: make schema-python-resource-bounds
55 changes: 55 additions & 0 deletions .github/workflows/schema-python-runs-hostile-corpus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: schema python hostile corpus

# THE PYTHON PORT'S SHARED HOSTILE-CORPUS GATE
# (schema-python-runs-hostile-corpus; docs/HOSTILE-CORPUS.md). Every committed
# hostile input is decoded by the port's generated table or packet reader and
# held to the manifest's verdict, named refusal and decoded-value digest.
#
# THE HEAVY PART IS NIGHTLY ONLY, so the lane stays inside the fast lane's
# one-minute budget: the full corpus replay runs on the schedule and on
# workflow_dispatch. A dispatch also runs the planted-reader control, which is
# seconds of work and proves the comparison has a blade. The runner reads files
# only: no network, no clock, no service.
#
# FORK SAFETY: every fleet job carries the fork guard so a fork's pull request
# never runs on fleet hardware.

on:
schedule:
- cron: '19 3 * * *'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || format('{0}-{1}', github.event_name, github.ref) }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
fast:
if: (github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
runs-on: [ self-hosted, Linux, X64, fleet, schema ]
timeout-minutes: 10
defaults:
run:
shell: go run ./tools/pgroup -- bash -e {0}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: the pinned Python interpreters
run: make dist-python
- name: the planted reader bug is red
run: make schema-python-runs-hostile-corpus-negative-control

nightly:
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: [ self-hosted, Linux, X64, fleet, schema ]
timeout-minutes: 10
defaults:
run:
shell: go run ./tools/pgroup -- bash -e {0}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: the pinned Python interpreters
run: make dist-python
- name: every shared hostile-corpus verdict, reason and digest
run: make schema-python-runs-hostile-corpus
- name: replay the corpus and require the planted reader bug to be observed
run: make schema-python-runs-hostile-corpus-negative-control
72 changes: 72 additions & 0 deletions docs/port-python/table-hostile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# The Python port on the shared hostile corpus and its resource bounds

This page holds the Python leg's P12 notes (docs/PORT-PYTHON.md, THE CARD MAP):
the shared hostile-corpus runner (docs/HOSTILE-CORPUS.md) and the bounded
memory/time gate on hostile text. No wire, text or runtime codec changed here;
the generated readers and the runtime are the ones the other Python cards
landed.

## The corpus runner

`TestPythonRunsHostileCorpus` (internal/codegen/pythontable/hostile_corpus_test.go)
reads the committed manifest and one raw input per case. It emits one generated
package per schema the manifest names — through the compiler driver, so a fixed
root keeps the recorded layouts its `schema.lock` carries — and runs one probe
under both pinned interpreters. The probe answers with the carrier's own API:

| carrier | generated call |
| --- | --- |
| `wire` | `Root.load(payload)` |
| `text` | `Root.from_json(text)` |
| `message` | `announce_read(vocab, ANNOUNCEMENT)`, then `load_messages(root, vocab, payload, capacity=1)` |
| `message_novocab` | `load_messages(root, fresh_vocab, payload, capacity=1)` |
| `announce`, `announce_second`, `announce_bytes`, `announce_entries` | `announce_read(vocab, payload[, max_bytes=8][, max_entries=1])`, the second announcement on the same vocabulary |
| `packet` | `Root.read(payload)` and `Root.write()` |

A refusal is mapped to the corpus's named reason: `text` answers `damaged`;
`wire` keeps `message_form_as_file`, `newer_form` and `non_finite_float`,
maps `count_over_extent_cap` to `count_refusal`, and answers `damaged` for
every other read refusal; a packet answers `packet_refused`; the message and
announcement carriers keep the runtime's own name (`no_vocabulary`,
`batch_too_large`, `second_announcement`, `vocabulary_too_large`). An accept's
digest is SHA-256 of `to_json()` without its trailing newline, which is the
engine's canonical text, or of the packet writer's bytes.

`TestPythonHostileCorpusPlantedReader` is the control: it admits form byte
`0xff` at the fixed-form gate in a scratch copy of the emitted runtime and
requires the comparison red by name (`wire-form-ff`: want `refuse/newer_form`,
got `refuse/damaged`). The tree is untouched.

`make schema-python-runs-hostile-corpus` is the gate and
`make schema-python-runs-hostile-corpus-negative-control` its control;
`.github/workflows/schema-python-runs-hostile-corpus.yml` runs the sweep and
the control nightly and on dispatch.

## The resource bounds

`TestPythonResourceBoundsHostileShapes` reads five hostile documents against one
generated table under both pins. Allocation is `tracemalloc`'s peak above the
read's start, and time is the count of executed line events (`sys.settrace`),
never wall clock. A read may allocate at most 256 times its input plus 1 MiB,
and may execute at most 128 line events per input byte plus 2^20.

| shape | input | verdict | allocated | budget | line events |
| --- | --- | --- | --- | --- | --- |
| deep nesting (132 nested lists) | 264 B | `Refused malformed` | 90,886 B | 1,116,160 B | 3,250 |
| huge count (100,000 elements past `[..1000]`) | 200,010 B | `Refused count_over_bound` | 13,020,312 B | 52,251,136 B | 6,400,156 |
| recursion (132 pointer bodies) | 3,050 B | `Refused malformed` | 125,571 B | 1,829,376 B | 29,737 |
| giant string (70,000 bytes) | 70,002 B | `Refused kind_mismatch` | 634,905 B | 18,969,088 B | 560,048 |
| many unknown fields (2,000 keys) | 20,891 B | accepted, counted | 407,416 B | 6,396,672 B | 279,169 |

The numbers are one run on the development bench; the assertions use the
budgets above and the documented refusal names, so a slower or faster machine
does not change the gate. There is no hot codec path in this card, so there is
no shape comparison or bench to report.

`TestPythonResourceBoundsPlantedPattern` raises the scanner's depth cap
(`if depth > 128:`) in a scratch copy of the emitted `json_scan.py` and
requires the deep shape to stop refusing as `malformed`; it changes to
`kind_mismatch`, and the control is red. `make schema-python-resource-bounds`
and `make schema-python-resource-bounds-negative-control` run the two gates;
`.github/workflows/schema-python-resource-bounds.yml` runs the sweep and the
control nightly and on dispatch.
6 changes: 6 additions & 0 deletions internal/ci/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,8 @@ func checkWorkflowPolicy(wfs map[string]string) []string {
"schema-luau-runs-hostile-corpus.yml:corpus",
"schema-luau-runs-hostile-corpus.yml:negative-control",
"schema-python-nightly-fuzz.yml:nightly",
"schema-python-resource-bounds.yml:nightly",
"schema-python-runs-hostile-corpus.yml:nightly",
"schema-rust-runs-hostile-corpus.yml:corpus",
"schema-rust-runs-hostile-corpus.yml:negative-control",
} {
Expand Down Expand Up @@ -1495,6 +1497,10 @@ func TestSelfHostedAdmissionAndDevIntegrationRoutes(t *testing.T) {
"schema-moo-nightly-fuzz.yml:nightly",
"schema-moo-nightly-fuzz.yml:wiring",
"schema-python-nightly-fuzz.yml:nightly",
"schema-python-resource-bounds.yml:fast",
"schema-python-resource-bounds.yml:nightly",
"schema-python-runs-hostile-corpus.yml:fast",
"schema-python-runs-hostile-corpus.yml:nightly",
"schema-rust-runs-hostile-corpus.yml:corpus",
"schema-rust-runs-hostile-corpus.yml:negative-control",
"schema-shared-hostile-corpus.yml:drift",
Expand Down
Loading
Loading