Conversation
Allocate and initialize mappings for all unsigned byte values, including 0xFF. Cast sequence and ctype inputs through unsigned char to avoid negative indexes and undefined behavior.
Include sstream where string streams are used and explicitly mark the file descriptor unused when posix_fadvise is unavailable.
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
This is a extra hardening over #1132 .
This PR makes substitution-matrix lookup tables cover the complete unsigned-byte range and prevents signed
charvalues from being used as negative array indexes.It also includes two small portability fixes discovered while validating the change.
Problem
The ASCII substitution matrix and
aa2nummappings usedUCHAR_MAXas an exclusive upper bound. BecauseUCHAR_MAXis itself a valid byte value, this omitted0xFFfrom the allocated and initialized ranges.Additionally, several scoring paths converted sequence characters directly to
int. On platforms wherecharis signed, bytes above0x7Fcould become negative indexes and cause out-of-bounds access.Character classification and conversion functions such as
isalphaandtoupperalso require their input to be representable asunsigned charorEOF.Changes
aa2numfor every value from0throughUCHAR_MAX.UCHAR_MAX.unsigned charbefore matrix indexing.unsigned char.X.<sstream>include in the search workflow.posix_fadvise.Validation
mmseqstarget successfully in the debug configuration.0x80and0xFF, under AddressSanitizer using a temporary regression harness.git diff --check.A permanent regression test is intentionally deferred until it can be integrated with an appropriate test framework.