matanper opened a new issue, #69859:
URL: https://github.com/apache/doris/issues/69859

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### Version
   
   4.1.4 (cloud mode). master is the same: 
`be/src/storage/index/inverted/clucene/clucene_index_reader.cpp:195` (null 
bitmap) and `:1019` (BKD doc ids):
   
   ```cpp
   *null_bitmap = roaring::Roaring::read(reinterpret_cast<char*>(buf.data()), 
false);
   ...
   visit(roaring::Roaring::read(doc_id.data(), false));
   ```
   
   ### Description
   
   The inverted index reader deserializes the null bitmap and BKD doc-id 
bitmaps with `roaring::Roaring::read(buf, portable=false)`, which trusts the 
serialized header and reads as far as it says. The buffer size 
(`null_bitmap_size`, `doc_id.size()`) is known but not passed. If those bytes 
are corrupt or truncated (a damaged cached block, a wrong slice location, a bad 
file), CRoaring reads past the buffer or allocates from garbage sizes, and the 
BE crashes (SIGSEGV / `std::bad_alloc` escaping the query) instead of failing 
the query.
   
   The newer SNII format already uses the bounded reader 
(`snii/format/null_bitmap.cpp:250`, `Roaring::readSafe(data, size)`), so only 
the CLucene-format path is affected. Index compaction reads the same null 
bitmaps and has the same exposure.
   
   ### Solution
   
   - Use `roaring::Roaring::readSafe(buf, size)` (or `Roaring::frozenView` with 
size checks) for both reads and return `Status::Corruption` when it fails or 
throws.
   - Catch `std::exception` around the deserialization and map it to a Status, 
so a corrupt bitmap fails the query or compaction rather than the process.
   - Optionally, when a cached copy fails to parse, re-read the bytes from 
remote storage once and evict the cached block if the remote copy parses.
   
   ### How to Reproduce?
   
   Corrupt (or truncate) the null bitmap file of an inverted index segment, 
e.g. flip bytes in the cached block in the file cache, then run a query that 
uses the index with a NULL-sensitive predicate (`col IS NULL`, `MATCH` on a 
nullable column). The BE crashes in `Roaring::read`.
   
   ### Anything Else?
   
   With bounded reads and the exception mapping, the same corrupt bitmaps fail 
only the affected query with a Corruption error.
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to