Repository navigation
Decode Hex and Base64 from a copy when the source overlaps the destination [patch] - #167
Merged
Merged
Conversation
…ation [patch] TryEncode copies an overlapping source to a pooled buffer first (#138), but TryDecode did not. With the destination starting after the source in the same buffer, Hex overwrote encoded pairs before reading them and Base64.DecodeFromUtf8, which does not support overlap, corrupted or rejected valid input. Both returned true with corrupted output in most cases, and the Hex and Base64 obfuscators' TryDeobfuscate forward to these decoders. TryDecode now does what TryEncode does: when the spans overlap, it decodes from a pooled copy and clears the copy before returning it. Decode-direction overlap tests sit next to the encode ones and cover every IEncodingProvider and IObfuscationProvider at offsets (0,0), (0,3) and (3,0). Fixes #166 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW6XNeWiDxG4BVzYTra
|
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.



Fixes #166
Problem
#138 made
TryEncode/TryObfuscatesafe for overlapping buffers, butTryDecodewas not. The problem appears when the destination starts after the source in the same buffer:Base64.DecodeFromUtf8directly, which does not support overlapping buffers.In most cases both returned
truewith corrupted output. The Hex and Base64 obfuscators'TryDeobfuscateforward to these decoders, so they were affected too.Change
HexEncodingProvider.TryDecodeandBase64EncodingProvider.TryDecodenow do whatTryEncodealready does. WhenencodedData.Overlaps(destination), they decode from anArrayPoolcopy and clear the copy before returning it to the pool. Each class's remarks now say that both directions copy on overlap.Tests
EncodingProviderTests.Decoding_OverlappingBuffers_MatchesOutOfPlacecovers everyIEncodingProvider, next to the existing encode overlap test.ObfuscationProviderTests.Deobfuscation_OverlappingBuffers_MatchesOutOfPlacecovers everyIObfuscationProvider, next to the existing obfuscate overlap test.Generated by Claude Code