Repository navigation
fix: arena only for sentinel ctx_offset; stable heap frames (issue #15) - #26
Merged
sleevetosleeve merged 1 commit intoNov 28, 2026
Merged
Conversation
Two fixes for the external decode context, found via the manual c-cpp.yml run on vlm_master (PKIX1 example, build-and-check job): 1. asn_get_struct_ctx() consulted the arena whenever the codec context carried one. The ANY text/JER/XER adapters (ANY.c ANY_text_prepare) decode through stack-temporary view structs whose address and specifics are reused across sequential ANY values, so arena frames keyed on them collided and the PKIX1 certificate failed to decode (check-ber). Now the arena is used only for ASN_CTX_OFFSET_EXTERNAL (-fno-ctx-members code); a real ctx_offset always resolves to the embedded member. The (st, type_key) frame keying stays: ext-mode code is all-sentinel, where offset-0 inline members still alias. 2. Heap-overflow frames were stored in a realloc-grown array of frames; decoders hold asn_struct_ctx_t* across nested decode calls, so growth left them dangling (heap-use-after-free in SET_OF_decode_ber on the PKIX1 certificate in ext mode, >8 live frames, ASan). The overflow is now an array of pointers to individually CALLOC'd frames; frame addresses are stable for the arena lifetime. check-ext-ctx additionally asserts frame pointers survive array growth. Verified: PKIX1 example make check passes in BOTH codegen modes (all formats, buffer sizes 1..8192, junk tests); certificate decodes under ASan in ext mode (42 frames) with clean free; tests-skeletons 71/71, tests-c-compiler 94/94, smoke 4/4 (incl. check-ext-ctx.sh, check-BER-retag, check-CER, check-issue-617), libasn1fix 5/5, check-610 pair 2/2. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-authored-by: sleevetosleeve <sleevetosleeve@users.noreply.github.com>
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
Fixes the
build-and-checkfailure from the manual c-cpp.yml run 46124008604 onvlm_master(PKIX1 example,check-ber:sample-Certificate-1.der: Decode failed ... Input processing error). Root cause was in the external decode context from #21/#22, in two parts:asn_get_struct_ctx()used the arena for anyctx_offsetwhen the codec context carried one. But the ANY text/JER/XER adapters (ANY.cANY_text_prepare) decode through stack-temporary view structs whose address and specifics are reused across sequential ANY values — so arena frames keyed on them collided and the certificate's second ANY decoded as already-finished (0 bytes). Fix: the arena is used only for theASN_CTX_OFFSET_EXTERNALsentinel (-fno-ctx-memberscode); a real offset always resolves to the embedded member. The(st, type_key)frame keying from feat: onboard converter-example, document and harden the external ctx (-fno-ctx-members, issue #15) #21 stays — ext-mode code is all-sentinel, where offset-0 inline members still alias.asn_struct_ctx_t *across nested decode calls, so growing the array (PKIX1 certificate in ext mode needs 42 frames) left those pointers dangling — heap-use-after-free inSET_OF_decode_berunder ASan. Fix: the overflow is now an array of pointers to individuallyCALLOC'd frames; frame addresses are stable for the arena's lifetime.check-ext-ctxnow also asserts frame pointers survive array growth.Bisection: example passed at d7d0f7e (post-#18), failed at 8d23fe6 (post-#21); 8d23fe6 skeletons + pre-#21 converter-example passed, isolating the converter/arena path; API repro showed plain
asn_decodeOK vsasn_decode_ctxfailing, then the ANY stack-view collision, then the UAF.Related issues
-fno-ctx-members) #15. Fixes the failure in manual run 46124008604 (job 140914436315).Type of change
Testing
make checkpasses in both codegen modes (default and-fno-ctx-members): all formats, buffer sizes 1/17/33/980/8192, junk tests — this is the exact CI step that failed.ASN_STRUCT_FREE_CTX.check-ext-ctx), tests-c-compiler 94/94, smoke 4/4 (check-ext-ctx.sh,check-BER-retag.sh,check-CER.sh,check-issue-617.sh), libasn1fix 5/5, check-610 pair 2/2.Checklist
vlm_masterexternal-ctx-design.mddecision log, ChangeLog)