Envisat: fix heap overflow in ScanForGCPs_ASAR from unchecked NUM_DSR#14941
Merged
Merged
Conversation
NUM_DSR from the GEOLOCATION GRID ADS sizes the GCP array via (nNumDSR + 1) * 11 evaluated as int, which overflows for a large declared count and under-allocates the array while the loop keeps writing 11 GCPs per record past its end. Reject a NUM_DSR that cannot fit the declared dataset size and compute the size in size_t, as ScanForGCPs_MERIS already does.
Collaborator
rouault
approved these changes
Jul 16, 2026
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.
What does this PR do?
EnvisatDataset::ScanForGCPs_ASAR()sizes the GCP array from theNUM_DSRfield of the GEOLOCATION GRID ADS descriptor:nNumDSRis taken verbatim from the dataset descriptor and(nNumDSR + 1) * 11is evaluated asint. A large declared count overflows:(390451572 + 1) * 11wraps to 7, so the array is under-allocated while the per-record loop keeps writing 11 GCPs per record throughGDALInitGCPs()past the end of the buffer.It triggers on a small crafted
.N1with a single 521-byte geolocation record andNUM_DSR=390451572. With-ftrapv(GDAL Debug builds) the multiply traps; without it AddressSanitizer reports:The fix stays in the callee: reject a
NUM_DSRthat cannot fit the declared dataset size, and compute the array size insize_t, the same wayScanForGCPs_MERIS()already does. Valid products read identically; the added test builds a well-formed geolocation grid that still yields 33 GCPs.What are related issues/pull requests?
None. Found by review of the GCP collection paths.
AI tool usage
Tasklist
Environment