Fix OOM in DataformatAwareCatalogSnapshot deserialization of corrupt input - #21236
Conversation
PR Reviewer Guide 🔍(Review updated until commit f8d44e8)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit f0041cc |
PR Code Suggestions ✨Latest suggestions up to f8d44e8 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit f8d44e8
Suggestions up to commit f8d44e8
Suggestions up to commit f8d44e8
Suggestions up to commit f0041cc
|
|
❕ Gradle check result for f0041cc: UNSTABLE Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21236 +/- ##
============================================
+ Coverage 73.28% 73.66% +0.37%
- Complexity 73483 74100 +617
============================================
Files 5912 5936 +24
Lines 334943 335730 +787
Branches 48257 48395 +138
============================================
+ Hits 245455 247299 +1844
+ Misses 69899 69003 -896
+ Partials 19589 19428 -161 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
f0041cc to
f8d44e8
Compare
|
Persistent review updated to latest commit f8d44e8 |
|
Persistent review updated to latest commit f8d44e8 |
|
❌ Gradle check result for f8d44e8: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Persistent review updated to latest commit f8d44e8 |
|
❌ Gradle check result for f8d44e8: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Persistent review updated to latest commit f8d44e8 |
…earch-project#21236) Signed-off-by: Kamal Nayan <askkamal@amazon.com> Co-authored-by: Kamal Nayan <askkamal@amazon.com> Signed-off-by: Abhishek Som <abhissom@amazon.com>
…earch-project#21236) Signed-off-by: Kamal Nayan <askkamal@amazon.com> Co-authored-by: Kamal Nayan <askkamal@amazon.com> Signed-off-by: Divya <divyruhil999@gmail.com>
…earch-project#21236) Signed-off-by: Kamal Nayan <askkamal@amazon.com> Co-authored-by: Kamal Nayan <askkamal@amazon.com>
…earch-project#21236) Signed-off-by: Kamal Nayan <askkamal@amazon.com> Co-authored-by: Kamal Nayan <askkamal@amazon.com>
Description
Problem
testDeserializationRejectsInvalidInputfails with OutOfMemoryError instead of the expected IOException when deserializing corrupt data.Failing test: https://build.ci.opensearch.org/job/gradle-check/74559/testReport/junit/org.opensearch.index.engine.exec.coord/DataformatAwareCatalogSnapshotTests/testDeserializationRejectsInvalidInput/
When random/corrupt bytes are deserialized, readVInt() can produce an arbitrarily large segmentCount. This value is passed directly to
new ArrayList<>(segmentCount), which attempts to allocate a massive backing array and triggers an OOM. Since OutOfMemoryError is an Error (not Exception), it
escapes the catch block in deserializeFromString.
Fix
Validate segmentCount against in.available() before allocating the list. Each segment must occupy at least 1 byte when serialized, so a segment count exceeding
the remaining bytes in the stream is guaranteed to be invalid. This is consistent with how Lucene's SegmentInfos validates segment counts during deserialization.
Test
Ran testDeserializationRejectsInvalidInput with the original failing seed (37AB7097D08B22E2) and 100 iterations — all pass.
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.