Skip to content

Fix DecodeObjectId unknown ext parse#10025

Open
embhorn wants to merge 3 commits intowolfSSL:masterfrom
embhorn:zd21392
Open

Fix DecodeObjectId unknown ext parse#10025
embhorn wants to merge 3 commits intowolfSSL:masterfrom
embhorn:zd21392

Conversation

@embhorn
Copy link
Member

@embhorn embhorn commented Mar 20, 2026

Description

Fixes in DecodeObjectID:

  • Moved the bounds check inside the y == 0 branch so that it checks *outSz < 2 before writing out[0] and out[1]. Previously the check y >= *outSz only validated one slot but the first-arc code writes two.
  • Changed sizeof(decOid) to MAX_OID_SZ in both DumpOID() and the WC_ASN_UNKNOWN_EXT_CB code path, so DecodeObjectId receives the correct element count (32) rather than the byte count (64).

Fixes zd21392

Testing

Added test_wc_DecodeObjectId

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@embhorn embhorn self-assigned this Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 13:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DecodeObjectId bounds check to require 2 output slots before writing the first two arcs.
  • Pass element counts (not byte sizes) to DecodeObjectId from DumpOID() 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 exercises DecodeObjectId directly, but doesn’t verify the corrected sizing behavior in DumpOID() (and similarly in the unknown-extension callback path). Consider adding a test that drives DumpOID()/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 incorrect outSz.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 20, 2026 16:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +928 to +930
#if !defined(NO_ASN) && \
(defined(HAVE_OID_DECODING) || defined(WOLFSSL_ASN_PRINT))
{
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +931 to +953
/* 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);
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
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.

2 participants