Fix DecodeObjectId unknown ext parse#10025
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes incorrect sizing and bounds-checking in OID decoding to prevent out-of-bounds writes and ensure correct arc decoding, and adds a regression test for DecodeObjectId.
Changes:
- Fix
DecodeObjectIdbounds check to require 2 output slots before writing the first two arcs. - Pass element counts (not byte sizes) to
DecodeObjectIdfromDumpOID()and unknown-extension callback path. - Add API test coverage for
DecodeObjectId, including the regression for the first-arc two-write case.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| wolfssl/wolfcrypt/asn.h | Exposes DecodeObjectId to tests and adds an OpenSSL-compat macro alias. |
| wolfcrypt/src/asn.c | Fixes bounds-checking in DecodeObjectId and corrects decOidSz units at call sites. |
| tests/api/test_asn.h | Registers new test_wc_DecodeObjectId test case. |
| tests/api/test_asn.c | Adds DecodeObjectId unit/regression tests. |
Comments suppressed due to low confidence (1)
wolfcrypt/src/asn.c:1
- The regression fix here is specifically about call sites passing the correct unit (element count vs byte size) into
DecodeObjectId. The newly added test exercisesDecodeObjectIddirectly, but doesn’t verify the corrected sizing behavior inDumpOID()(and similarly in the unknown-extension callback path). Consider adding a test that drivesDumpOID()/ASN print (or a known unknown-extension callback invocation) far enough to ensure these call sites decode the full OID rather than failing/truncating due to an incorrectoutSz.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if !defined(NO_ASN) && \ | ||
| (defined(HAVE_OID_DECODING) || defined(WOLFSSL_ASN_PRINT)) | ||
| { |
There was a problem hiding this comment.
The test’s compile guard doesn’t include OPENSSL_ALL, but the header enables the DecodeObjectId mapping/prototype under (HAVE_OID_DECODING || WOLFSSL_ASN_PRINT || OPENSSL_ALL). To avoid leaving this behavior untested in configurations where OPENSSL_ALL is set without the other two flags, align the test guard with the header condition.
| /* OID 1.2.840.113549.1.1.11 (sha256WithRSAEncryption) | ||
| * DER encoding: 2a 86 48 86 f7 0d 01 01 0b | ||
| * First byte 0x2a = 42 => arc0 = 42/40 = 1, arc1 = 42%40 = 2 | ||
| * Remaining arcs: 840, 113549, 1, 1, 11 | ||
| */ | ||
| static const byte oid_sha256rsa[] = { | ||
| 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b | ||
| }; | ||
| word16 out[MAX_OID_SZ]; | ||
| word32 outSz; | ||
|
|
||
| /* Test 1: Normal decode */ | ||
| outSz = MAX_OID_SZ; | ||
| ExpectIntEQ(DecodeObjectId(oid_sha256rsa, sizeof(oid_sha256rsa), | ||
| out, &outSz), 0); | ||
| ExpectIntEQ((int)outSz, 7); | ||
| ExpectIntEQ(out[0], 1); | ||
| ExpectIntEQ(out[1], 2); | ||
| ExpectIntEQ(out[2], 840); | ||
| ExpectIntEQ(out[3], (word16)113549); /* truncated to word16 */ | ||
| ExpectIntEQ(out[4], 1); | ||
| ExpectIntEQ(out[5], 1); | ||
| ExpectIntEQ(out[6], 11); |
There was a problem hiding this comment.
This test relies on truncation of the 113549 arc into word16, which makes the expected value less intuitive and ties the test to the current (potentially undesirable) width limitation rather than the decode logic you’re targeting. Consider switching to an OID where all arcs fit in word16 (while still exercising multi-byte base-128 decoding), so assertions remain exact and clearer (e.g., an OID with arcs like 840 and 10045 rather than 113549).
Description
Fixes in
DecodeObjectID:y == 0branch so that it checks*outSz < 2before writing out[0] and out[1]. Previously the checky >= *outSzonly validated one slot but the first-arc code writes two.sizeof(decOid)toMAX_OID_SZin bothDumpOID()and theWC_ASN_UNKNOWN_EXT_CBcode path, soDecodeObjectIdreceives the correct element count (32) rather than the byte count (64).Fixes zd21392
Testing
Added
test_wc_DecodeObjectIdChecklist