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.
This is a simple addition of a few bounds checks to ensure that the
dirsDepth
array is not accessed at an index beyond its size.Type of change
Description
This change adds index checks before
dirDepths[collectionIndexDirDepth]
anddirDepths[collectionNameDepth]
to avoid indexing beyond the end of the array. We could just check for thecollectionIndexDirDepth
and avoid the other two, but that would be more brittle in case the constants defined a few lines earlier were reordered. We could also just calculatelen(dirsDepth)
once as a small perf improvement.Additional details
I have never used Hyperledger, and did not test this change in any way. I also don't know how likely it would be for
dirDepths
to short enough to cause the panic.Related issues
This is related to the suggestion from @manish-sethi in #1080.