Repository navigation
Sync upstream mouse07410/asn1c vlm_master (b4265af8c) into fork - #68
Merged
Merged
Conversation
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>
Owner
Author
|
Self-review rubric (sync PR, head
Protected-path note: the diff matches This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
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.
Summary
vlm_masteris brought level with upstreammouse07410/asn1cvlm_masteratb4265af8c(27 upstream commits since the last sync point6e35021aa). Upstream's push CI onb4265af8cis green for both the C/C++ CI and Rust backend workflows; the intermediate red shadd684e2b0is superseded.--strict-modefor C and Rust, fixed-size named BIT STRING JER normalization (JER cannot encode a fixed-size BIT STRING with trailing zero bits mouse07410/asn1c#617/fix(skeletons): pad short BIT STRING values to a fixed JER size mouse07410/asn1c#618), APER CHOICE extension validation (APER CHOICE with no extension additions accepts a malformed extension encoding mouse07410/asn1c#615/fix(skeletons): reject invalid APER CHOICE extension encodings mouse07410/asn1c#616), exact signed-minimum printing (The printed minimum INTEGER value is off by one mouse07410/asn1c#613/fix(asn1parser): format the signed minimum exactly mouse07410/asn1c#614), PER range widths without signed overflow (PER constraint width is wrong for the full INTEGER range mouse07410/asn1c#611/fix(asn1c): derive PER range width from the unsigned span mouse07410/asn1c#612), reversed/boundary constraint range rejection (Reversed constraint ranges abort the compiler instead of reporting an empty range mouse07410/asn1c#605–fix(asn1fix): guard range endpoints by the asn1c_integer_t limits mouse07410/asn1c#608), and the range-watchdog test hardening (test(tests-asn1c-compiler): stop the range watchdog reporting false timeouts mouse07410/asn1c#609/test(tests-asn1c-compiler): range watchdog false timeouts + deadline-masked pass fix (#609 + follow-up) mouse07410/asn1c#610).asn1c/asn1c.c— upstream'sasn1c_extract_long_switches()call (which adds--strict-mode) is taken, while the fork's removal of the dead-Lfrom the getopt option string (fork cli: drop the dead -L from the getopt option string #33) is kept. Nocase 'L'handler exists on either side.ChangeLog— both the fork's and upstream's new "Changes since v1.5.3" entries are kept, fork entries first so the fork's asn1c: standard modules load in readdir() order, so generated descriptor indexes vary by filesystem #52 entry's "upstream implementation below" reference stays correct.--merge, not squash.No tracking issue — routine upstream sync (Phase 1 of the dev loop).
Test plan
make,make check,make distcheck, and the PKIX1 roundtrip job before merge.git grepfor<<<<<<</>>>>>>>is empty).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/andlibasn1compiler/and needs its own CI gate. Upstreammouse07410/asn1chas 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