fix: key detector coordinates by detector ID and bounds check array a… - #272
Open
aria-googler wants to merge 1 commit into
Open
fix: key detector coordinates by detector ID and bounds check array a…#272aria-googler wants to merge 1 commit into
aria-googler wants to merge 1 commit into
Conversation
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
Fixes an unchecked heap out-of-bounds write vulnerability and coordinate mismatch in
get_detector_coordsandSimplexDecoderwhen parsing Detector Error Model (.dem) files containing duplicate, sparse, or out-of-order detector coordinate declarations.Root Cause & Problem
Sequential Appending in
get_detector_coords:Previously,
get_detector_coordsinsrc/utils.ccappended coordinate vectors sequentially asDEM_DETECTORinstructions were encountered, rather than mapping coordinates to target detector IDs (target.val()).detector(0,0,1) D0anddetector(0,0,2) D0),detector_coords.size()became greater thandem.count_detectors().detector(1,2,3) D5),detector_coords[0]held the coordinates for5.Unchecked Heap Writes:
In
SimplexDecoder(src/simplex.cc) andbuild_det_orders_coordinate(src/utils.cc), iteration loops ran up todetector_coords.size()and wrote into buffers (detector_t_coordsandinner_products) sized todem.count_detectors(). Whendetector_coords.size() > dem.count_detectors(), an out-of-bounds heap write occurred.Key Changes
Detector ID Keying (
src/utils.cc):get_detector_coordsto allocate adetector_coordsvector of sizedem.count_detectors()and store coordinates atdetector_coords[det_id]usingtarget.val().{}when noDEM_DETECTORinstructions are present in the DEM.Defensive Bounds Checking (
src/simplex.cc&src/utils.cc):std::min(...)bounds checking inSimplexDecoder::SimplexDecoderandbuild_det_orders_coordinateto guarantee loop indices never exceed allocation sizes.Unit Tests (
src/tesseract.test.cc):TEST(utils, DuplicateDetectorCoords)andTEST(simplex, DuplicateDetectorCoords)to verify safe coordinate mapping and non-crashing behavior on DEM files with duplicate detector coordinate declarations.Verification & Testing
clang-format -imatching repository CI guidelines.bazel test //src/...