Skip to content

Sync upstream mouse07410/asn1c vlm_master (b4265af8c) into fork - #68

Merged
dmccoystephenson merged 28 commits into
vlm_masterfrom
sync/upstream-2026-11-19
Nov 20, 2026
Merged

dmccoystephenson merged 28 commits into
vlm_masterfrom
sync/upstream-2026-11-19

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Owner

Summary

No tracking issue — routine upstream sync (Phase 1 of the dev loop).

Test plan

  • CI must pass make, make check, make distcheck, and the PKIX1 roundtrip job before merge.
  • Rust backend workflow green on the PR head.
  • No conflict markers remain (git grep for <<<<<<< / >>>>>>> is empty).
  • Local build: UNVERIFIED — autotools/make cannot be executed in this environment; the CI run on the PR head is the anchor.

Triage notes

Open fork issues #61, #54, #30, #19, #7 were not picked this cycle: the cycle was spent on the upstream sync, which touches skeletons/ and libasn1compiler/ and needs its own CI gate. Upstream mouse07410/asn1c has no open issues.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code

drafted by Claude on behalf of Daniel Stephenson

Mouse and others added 28 commits November 13, 2026 18:42
A value, SIZE or FROM constraint whose lower bound is greater than its upper
bound was built as a normal range and then intersected with the parent type's
range. _range_split() asserts that both operands are non-empty, so
INTEGER (5..1), SIZE (1..0), FROM ("Z".."A") and the inner range of REAL WITH
COMPONENTS aborted the compiler instead of diagnosing the input.

After both endpoints have been filled in, reject a simple interval
(el_count == 0) whose left edge sorts after its right edge: report
"Constraint range ... is empty", free the range and return NULL with EPERM,
which the fixer turns into the existing diagnostics. The check is restricted
to simple intervals because a multi-character FROM("abc") is represented as a
set of singleton elements whose parent edges are deliberately inverted. The
REAL WITH COMPONENTS caller now NULL-checks the inner range instead of
asserting.

Add check-reversed-ranges.sh: 9 empty forms must exit 65 with the diagnostic
and 7 neighbouring forms (including FROM("abc")) must still be accepted. On
vlm_master the first form aborts with SIGABRT; with this change the suite
passes.
The code that splits and subtracts constraint ranges moves an endpoint by
one, and it guarded that move with INTMAX_MIN/INTMAX_MAX. Those are the
intmax_t limits, but asn1c_integer_t is __int128 when the build supports it,
so at the real limits the guard did not fire: the largest value was
incremented and the smallest decremented, which is signed overflow. The
wrapped endpoint corrupts the range and the fixer keeps allocating range
pieces, so a schema as simple as

    T ::= INTEGER (0..170141183460469231731687303715884105727)

makes asn1c hang instead of compiling.

Compare the four guards against ASN_INTEGER_MAX/ASN_INTEGER_MIN instead. At
the true limit no adjacent value exists, so the piece beyond it is correctly
omitted; nothing is saturated. The two macros move from asn1p_integer.c to
asn1p_integer.h so the fixer can use them; their definition is unchanged.

The new check-boundary-ranges.sh compiles ranges ending at both limits and
the mixed -1..MAX case under a timeout, with 2^126 and MAX-1 as controls. On
vlm_master the three limit cases time out after 10s; with this change they
pass, tests-asn1c-compiler is 13/13 and tests-c-compiler 92/92.
Validate issue mouse07410#605, preserve REAL error propagation, document denial-of-service mitigation, and support gtimeout in regression tests.
…ger width

Validate issue mouse07410#607 with permanent split/subtraction result assertions, configured-width regression inputs, UBSan probes, and documented test prerequisites.
…imeouts

The reversed-range watchdog started a timer subshell after installing
deferred HUP/INT/TERM traps. A subshell can run with the caller's traps
until it installs its own, so a cancel delivered in that window could be
lost: the timer slept to its deadline and marked a timeout even though
asn1c had already printed its diagnostic and exited. On the machine where
this was found the script failed nine of ten runs.

Write a cancel file before signalling the watchdog and let its sleep poll
that file in one-second steps, so a missed signal costs at most a second.
Check the compiler is still alive before marking, and map the case to a
timeout (124) only when the marker exists and the wait status is a signal
(>= 128); a compiler that exited normally keeps its real status. The
two-second TERM to KILL grace stays unconditional so escalation still
runs.

20 consecutive runs now pass. A sleeping fake compiler is still killed
and reported as a timeout for all 16 cases (10 s each), and one that
ignores TERM is killed after the grace (about 12 s each); no child
survives the run. tests-asn1c-compiler is 14/14.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
test(tests-asn1c-compiler): range watchdog false timeouts + deadline-masked pass fix (mouse07410#609 + follow-up)
The PER constraint emitter computed how many values a range holds as
"1 + right - left" in asn1c_integer_t, then doubled a signed cover value
until it reached that count. Both steps overflow when a range covers most of
the type. On a build where asn1c_integer_t is intmax_t (no __int128), the
full range MIN..MAX wraps the count to 0, so the emitted constraint says
APC_CONSTRAINED with range_bits 0 instead of 64; the addition itself is
signed overflow. INTEGER (INTMAX_MIN..INTMAX_MAX) is a legal type,
so its constraint metadata must be right.

Compute the width from the unsigned span right - left instead. The span
always fits the unsigned counterpart of asn1c_integer_t, so neither the
subtraction nor the bit count can overflow, and the bit length of the span is
exactly the old range_bits (the smallest k with span < 2^k). Add
asn1c_uinteger_t, asn1p_unsigned_bit_length() and asn1p_range_bit_length()
next to asn1c_integer_t, and pin the boundary values in the existing
libasn1parser unit test. The doubling loop and its error path, which set
rbits = sizeof(r) (bytes, not bits) and cannot be reached with the span
form, are removed.

The boundary script gains two code-generation cases: the full signed 64-bit
range must emit APC_CONSTRAINED, 64, and 0..INTMAX_MAX must emit 63. On an
intmax_t build of vlm_master the first case emits 0 and fails; with this
change both pass. The script also stops requiring timeout/gtimeout (absent
on a standard macOS install): a POSIX sleep/kill timer records a timeout
only while the compiler is still running, and the boundary test's .log
target joins the $(ASN1C) prerequisite rule so a focused or parallel check
cannot run it before the compiler is built.

The boundary timer mirrors the reversed-range timer: a deadline is
authoritative, so a compiler that catches TERM and exits 0 is still reported
as a timeout. WATCHDOG_DEADLINE overrides the ten-second deadline, and the
script carries in-tree self-tests for prompt exit, a hang, a graceful TERM
exit 0, an ignored TERM (KILL) and invalid deadline forms. The timer
validates WATCHDOG_DEADLINE (empty, oversized and out-of-range values are
rejected before any temp file is created) and cleans up the compiler and
timer if the script is interrupted. The eight boundary cases, the five
watchdog rows and the invalid-deadline forms pass on both widths;
libasn1parser is 1/1 and tests-asn1c-compiler 14/14, with
tests-c-compiler 92/92 unchanged.
Retain Javier (@mr-j0nes) as the original author of the unsigned-span fix. Document issue mouse07410#611, all Copilot findings, independent security review, C/Rust validation and known limits. Strengthen bit-boundary and generated Rust tests, keep the C emitter units within the complexity bound, and reap portable-watchdog children reliably.
…d overflow

Fixes mouse07410#611. Original unsigned-span fix and initial regressions by Javier (@mr-j0nes); his commit is preserved.

Reviewed all Copilot comments and the C/Rust PER paths. Maintainer follow-up 324ba8f strengthens boundary coverage, documents the security review, hardens watchdog lifecycle management, and bounds emitter complexity. No new consequential vulnerability was identified in the reviewed paths.

Local validation includes the reproduced base UBSan failure, fixed no-__int128 ASan/UBSan checks, native C compiler regressions, generated C/Rust PER boundary tests, 269 Rust runtime tests, and exact all-target/all-feature pedantic/nursery strict Clippy. Final GitHub build-and-check, clang-sanitizers, distcheck, and generated-codecs checks passed before merge.

See docs/issue-611-review.md and the PR review for details and known pre-existing limitations, including signed-minimum C literal warnings and no128 parsing-reference differences. No actual 32-bit target execution or extended fuzzing was performed.
asn1p_itoa_s() handled values that do not fit long by negating them to
obtain the magnitude, which overflows for ASN_INTEGER_MIN. It worked
around that with two hard-coded strings, and both were wrong: the
128-bit literal ended in ...729 instead of ...728 and the 64-bit one in
...809 instead of ...808. The branch also returned 41 and 21, counting
the terminating NUL, although the header promises the length of the
numeric value (40 and 20).

Compute the magnitude in asn1c_uinteger_t instead: converting to
unsigned and subtracting from zero is defined for every value and yields
|v| even for the minimum. Split that magnitude with unsigned arithmetic
and keep the existing nine-digit padding and the long fast path. The
width-specific literals, the negation and the switch are gone, so the
result no longer depends on long or on the configured width.

Extend the libasn1parser unit test with exact strings, return lengths and
the buffer-size contract, including both limits and their neighbours.
The boundary script now also checks that
-E -F prints the exact minimum, since the old value could not be
re-parsed.
An extensible APER CHOICE with no extension additions did not reject the
extension bit: it reused the bit as a member index and decoded the following
bytes as an open type, so it could select a member that was never encoded.
Reject the extension-bit encoding when the CHOICE defines no extension
additions, and fail cleanly when a selected member or an open-type target has
no APER decoder instead of calling a NULL function pointer. Valid
alternatives and valid extension additions keep decoding.

Add a skeleton regression that drives the three paths with a local NULL-codec
type, next to the valid root alternatives and a valid extension addition. On
vlm_master the extension-bit-only input returns RC_WMORE instead of RC_FAIL,
and the NULL-decoder row crashes with an AddressSanitizer SEGV; with this
change all three rows return RC_FAIL, tests-skeletons is 70/70,
tests-asn1c-compiler 14/14, tests-c-compiler 92/92 and
tests-randomized 20/20 (FUZZ_TIME=1).
Expose --strict-mode without changing the default interoperability profile.
Use X.691 NKM constraint visibility, validate public C codec boundaries,
and tighten syntax, Unicode, padding and DER input policies. Preserve valid
unknown extensions and propagate the policy into generated Rust runtimes.

Document standards references, support limits and API contracts. Add
cross-format default/strict, malformed-input, extension-relay and CLI tests.
Validation includes C ASan/UBSan, both Rust runtime feature profiles,
generated-code tests, strict Clippy and individual-codec compile checks.
# Conflicts:
#	libasn1parser/asn1p_integer.c
#	libasn1parser/check_asn1p_integer.c
# Conflicts:
#	skeletons/constr_CHOICE_aper.c
#	tests/tests-skeletons/check-APER-CHOICE-extension.c
A BIT STRING with SIZE(8) is eight bits wide, but a value such as one
decoded from BER can carry trailing zero bits in a compact form: one
significant bit with seven insignificant zeros. The JER encoder compared
the one-bit width with the required eight and rejected the value instead of
padding it, so re-encoding that value to JER failed while XER and BER
handled it.

Accept a value whose meaningful bits fit the fixed size and emit the full
width, zero-filled. A value whose declared width exceeds the size is still
rejected. The fixed-size cases in check-JER cover one-bit and full-byte
values, widths 8/16/9, a non-byte-aligned value, the empty value, the two
rejections, a callback failure and a decode/re-encode round trip.
Honor X.697 24.2.2 by padding or trimming only trailing zeros for NamedBitList types. Preserve JER SIZE metadata through type references, recognize equivalent named-bit values during strict validation, and exercise generated C and Rust boundaries.
Apply X.697 24.2.2 to fixed-size BIT STRING types with a NamedBitList.
Pad or trim trailing zeros to the required width and reject significant bits
beyond it. Preserve exact widths for unnamed values and carry fixed-size JER
metadata through aliases and constrained references. Cover default and strict
C code generation and the Rust backend's named-bit support boundary.

Fixes mouse07410#617
Conflicts resolved:
- asn1c/asn1c.c: take upstream's asn1c_extract_long_switches()
  (--strict-mode) while keeping the fork's removal of the dead -L
  from the getopt option string (#33).
- ChangeLog: keep both the fork's and upstream's new entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Owner Author

Self-review rubric (sync PR, head 5a1a13e36):

  • Scope: PASS — the only fork-authored content is the two hand-resolved conflict hunks (asn1c/asn1c.c getopt line, ChangeLog entry order); every other changed file is upstream's 27 commits from 6e35021aa..b4265af8c.
  • Conflict resolution: PASS — resolved from the fork's merge-base delta, not the whole HEAD side. git diff upstream/vlm_master -- asn1c/asn1c.c shows only pre-existing fork deltas (dead -L removed per fork cli: drop the dead -L from the getopt option string #33, -gen-autotools re-accepted, fork usage-text additions); upstream's asn1c_extract_long_switches() / --strict-mode is kept intact.
  • Tests-new / Tests-fix: no signal — no fork-authored code or tests; upstream's own regressions (PER range width, APER CHOICE extensions, JER BIT STRING, reversed ranges) arrive with their fixes.
  • Sibling structure / renames: PASS — upstream renamed asn1c_extract_rust_switch to asn1c_extract_long_switches; the merged file has no remaining reference to the old name (the call site in the resolved hunk uses the new one).
  • Docs: PASS — ChangeLog carries both sides' entries, fork entries first so the fork asn1c: standard modules load in readdir() order, so generated descriptor indexes vary by filesystem #52 entry's "upstream implementation below" reference still holds; upstream's docs/strict-mode*.md and man-page updates arrive unchanged.
  • CI: PASS — C/C++ CI (build-and-check, clang-sanitizers, distcheck, generated-codecs) and Rust backend are green on the PR head. Upstream push CI on b4265af8c was green for both workflows before the sync was started.
  • No-new-warnings: PASS — clang-sanitizers and build-and-check are green; no fork-side C change beyond the getopt string.
  • Roundtrip-preserved: PASS — build-and-check and generated-codecs green on the head.
  • Skeleton-blast-radius: no signal for fork-authored change — skeletons/ edits are upstream's, already green upstream and here.
  • No-leak / ChangeLog: PASS — clang-sanitizers green; ChangeLog updated.

Protected-path note: the diff matches skeletons/*, Makefile.am and libasn1compiler/* on the do-not-auto-merge list, as every upstream sync does; this dispatch is operator pre-authorized to merge, and the protected content is upstream-authored and CI-green on both sides. Local build was UNVERIFIED (no make/autotools execution in this environment); the CI run on the exact head SHA is the anchor. To be merged with --merge (not squash) so future syncs stay merges.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 32b0a0d into vlm_master Nov 20, 2026
4 checks passed
@dmccoystephenson
dmccoystephenson deleted the sync/upstream-2026-11-19 branch November 20, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants