Skip to content

fix(OtherFunctions): correct base16 decode, base64 footer append, duplicate .asf entry, mp3 comment - #30

Merged
mrjimenez merged 3 commits into
amule-org:masterfrom
mrjimenez:worktree-pr-ia
Jun 9, 2026
Merged

fix(OtherFunctions): correct base16 decode, base64 footer append, duplicate .asf entry, mp3 comment#30
mrjimenez merged 3 commits into
amule-org:masterfrom
mrjimenez:worktree-pr-ia

Conversation

@mrjimenez

@mrjimenez mrjimenez commented Jun 9, 2026

Copy link
Copy Markdown

Summary

  • base16 decode silent corruption: base16Lookup mapped ':' through '@' (ASCII 58–64) to 0x9; these are not valid hex digits and fall within the valid lookup range, so they bypassed the out-of-range guard and silently produced wrong output. Fixed by mapping them to the 0xFF invalid sentinel, and added a guard in DecodeBase16 to return 0 on the first invalid character.
  • base64 footer overwrites encoded content: EncodeBase64 used = instead of += when appending the -----END ...----- footer, discarding all previously encoded data. Fixed to +=.
  • duplicate .asf map entry: ED2KFileTypesMap inserted .asf twice. Removed the second entry.
  • incorrect .mp3 comment: // MPEG-3 Audio File corrected to // MPEG-1/2 Audio Layer 3 File.

Tests added

Added unittests/tests/OtherFunctionsTest.cpp with five cases, verified to fail against the pre-fix code and pass after:

Test What it checks Catches
Base16/RoundTrip EncodeBase16 + DecodeBase16 round-trip on 0xDEADBEEF general correctness
Base16/RejectsNonHexChars DecodeBase16 returns 0 for each of ':' ';' '<' '=' '>' '?' '@' base16 lookup bug
Base16/RejectsOddLength DecodeBase16 returns 0 for odd-length input existing contract
Base64/HeaderAndFooterBothPresent EncodeBase64 with header "TEST" on input "Man" produces output containing -----BEGIN TEST-----, TWFu, and -----END TEST----- in order base64 footer overwrite bug
Base64/NoHeaderProducesPlainBase64 Without a header, output is plain Base64 with no PEM framing regression guard

SetBase64Header() was added to OtherFunctions.h/.cpp to expose the file-static strHeaderLine for test setup.

Test plan

  • OtherFunctionsTest passes (ctest -R OtherFunctionsTest)
  • Same tests confirmed to fail against pre-fix code
  • Full build passes without new warnings

mrjimenez added 3 commits June 8, 2026 23:22
…licate .asf

- base16Lookup entries for ':' through '@' were incorrectly mapped to 0x9;
  they are not valid hex digits so map them to the 0xFF invalid sentinel
- DecodeBase16 did not check for the 0xFF sentinel before writing to the
  output buffer, causing silent corruption on invalid input; add guard
- EncodeBase64 used assignment instead of append when writing the footer
  line, discarding all encoded content (pbBufferOut = → +=)
- ED2KFileTypesMap inserted ".asf" twice; remove the duplicate entry
MP3 is MPEG-1 Audio Layer 3 (or MPEG-2 Audio Layer 3), not "MPEG-3".
…64 encode

Add OtherFunctionsTest covering:
- DecodeBase16 round-trip correctness
- DecodeBase16 returning 0 on non-hex characters ':' through '@'
- DecodeBase16 returning 0 on odd-length input
- EncodeBase64 preserving encoded content when a PEM header is set

Add SetBase64Header() to expose the file-static strHeaderLine so the
PEM header/footer path of EncodeBase64 can be exercised from tests.
@mrjimenez
mrjimenez merged commit 13635bb into amule-org:master Jun 9, 2026
9 checks passed
@mrjimenez
mrjimenez deleted the worktree-pr-ia branch June 9, 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.

1 participant