Skip to content

refactor: read only nullindex - #9019

Merged
dancixx merged 7 commits into
devfrom
refactor/read-only-nullindex
May 12, 2026
Merged

dancixx merged 7 commits into
devfrom
refactor/read-only-nullindex

Conversation

@dancixx

@dancixx dancixx commented May 12, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

⚠️ PRs must target the dev branch. If your PR targets master, please change the base branch to dev before requesting a review.

  • My PR targets the dev branch (not master) and my branch was created from dev.
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --workspace --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dancixx
dancixx marked this pull request as ready for review May 12, 2026 14:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/segment/src/common/flags/read_only_roaring_flags.rs`:
- Around line 42-94: The compiler error occurs because
read_only_roaring_flags::open reads DynamicFlagsStatus and calls .len() on its
private field; fix by exposing the length via a public accessor on
DynamicFlagsStatus (e.g., add a pub fn len(&self) -> usize in
dynamic_stored_flags.rs) and use that accessor here (call
status_storage.read_whole()?[0].len()), or alternatively make the len field
pub/pub(super) in DynamicFlagsStatus and recompile; update references to use the
new public API so the code no longer tries to access a private field directly.

In `@lib/segment/src/common/flags/roaring_flags.rs`:
- Around line 37-43: iter_falses currently does an unchecked cast of self.len()
into PointOffsetType which can silently truncate large lengths; replace the raw
"as" cast with a checked conversion (e.g. use
PointOffsetType::try_from(self.len()) or usize::try_into()) and handle the Err
case explicitly (either return an empty iterator or panic with a clear message)
before creating the range and calling get_bitmap(); update the code in
iter_falses to use the checked value (len_u32) when building (0..len_u32) so no
silent truncation occurs.

In `@lib/segment/src/index/field_index/null_index/shared.rs`:
- Around line 34-36: The doc comment currently uses the misspelled word
"Implementors"; change it to "Implementers" in the comment that documents the
trait exposing `has_values_flags`, `is_null_flags`, `total_point_count`, and
`telemetry_index_type` (the comment block in shared.rs), so the line reads
"Implementers expose four required pieces ..." to satisfy codespell.
- Around line 128-149: The code casts has_values_flags.len(),
is_null_flags.len(), and total_point_count to PointOffsetType (u32) without
checking for overflow; add explicit checked conversions (e.g.,
PointOffsetType::try_from(...) or usize::try_into()) for the values used in the
range expressions in shared.rs so overflows are detected before casting, and
propagate/handle the error (return an Err or a safe fallback iterator) instead
of silently truncating; update the two range constructions that use
end..total_point_count as PointOffsetType and any uses of end = ... as
PointOffsetType to use the checked conversion and appropriate error handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a36ba527-6ec2-4f5f-a2ab-ed6fcb9c7017

📥 Commits

Reviewing files that changed from the base of the PR and between 1f99a0b and c0483f2.

📒 Files selected for processing (12)
  • lib/segment/src/common/flags/dynamic_stored_flags.rs
  • lib/segment/src/common/flags/mod.rs
  • lib/segment/src/common/flags/read_only_roaring_flags.rs
  • lib/segment/src/common/flags/roaring_flags.rs
  • lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
  • lib/segment/src/index/field_index/field_index_base/field_index.rs
  • lib/segment/src/index/field_index/field_index_base/field_index_read_impl.rs
  • lib/segment/src/index/field_index/null_index/immutable_null_index.rs
  • lib/segment/src/index/field_index/null_index/mod.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/index/field_index/null_index/read_only_null_index.rs
  • lib/segment/src/index/field_index/null_index/shared.rs

Comment on lines +37 to +43
fn iter_falses(&self) -> Box<dyn Iterator<Item = PointOffsetType> + '_> {
// potential optimization:
// Create custom iterator which leverages bitmap's iterator for knowing ranges where the flags are false.
// This will help by not checking the bitmap for indices that are already known to be false.
let len = self.len() as PointOffsetType;
let bitmap = self.get_bitmap();
Box::new((0..len).filter(move |i| !bitmap.contains(*i)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

# First, read the specific lines mentioned in the review
cat -n lib/segment/src/common/flags/roaring_flags.rs | sed -n '35,45p'

Repository: qdrant/qdrant

Length of output: 640


🏁 Script executed:

# Find the definition of PointOffsetType
rg "type PointOffsetType|PointOffsetType\s*=" --type rs -A 2 | head -30

Repository: qdrant/qdrant

Length of output: 84


🏁 Script executed:

# Check if there's validation of length before the cast
rg "iter_falses" -B 5 -A 15 lib/segment/src/common/flags/roaring_flags.rs

Repository: qdrant/qdrant

Length of output: 1992


🏁 Script executed:

# Find PointOffsetType definition
rg "type PointOffsetType" --multiline-dotall -A 2 | head -30

Repository: qdrant/qdrant

Length of output: 279


🏁 Script executed:

# Also check in common module
rg "PointOffsetType" lib/segment/src/ -l | head -5

Repository: qdrant/qdrant

Length of output: 417


🏁 Script executed:

# Look at the whole file to understand context better
head -100 lib/segment/src/common/flags/roaring_flags.rs

Repository: qdrant/qdrant

Length of output: 3292


🏁 Script executed:

# Search for constraints on segment/point count or PointOffsetType limits
rg "u32::MAX|PointOffsetType::MAX|MAX_POINTS|POINT_OFFSET" lib/segment/src/ | head -20

Repository: qdrant/qdrant

Length of output: 2184


🏁 Script executed:

# Check how RoaringBitmap is constructed and if there are constraints
rg "RoaringBitmap::new|insert|len" lib/segment/src/common/flags/ -B 2 -A 2 | head -40

Repository: qdrant/qdrant

Length of output: 2753


🏁 Script executed:

# Look for any segment size limits or validation
rg "max.*point|point.*max|segment.*size" lib/segment/src/ -i | head -20

Repository: qdrant/qdrant

Length of output: 2197


Guard the usize → PointOffsetType cast in iter_falses.

Line 41 narrows self.len() with an unchecked as cast. If the roaring flags length ever exceeds PointOffsetType::MAX (u32::MAX), this silently truncates the iterator range and skips false entries. The codebase demonstrates awareness of this boundary in id_tracker/compressed/versions_store.rs where it explicitly validates the u32::MAX constraint.

Suggested fix
-        let len = self.len() as PointOffsetType;
+        let len = PointOffsetType::try_from(self.len())
+            .expect("roaring flags length must fit into PointOffsetType");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/segment/src/common/flags/roaring_flags.rs` around lines 37 - 43,
iter_falses currently does an unchecked cast of self.len() into PointOffsetType
which can silently truncate large lengths; replace the raw "as" cast with a
checked conversion (e.g. use PointOffsetType::try_from(self.len()) or
usize::try_into()) and handle the Err case explicitly (either return an empty
iterator or panic with a clear message) before creating the range and calling
get_bitmap(); update the code in iter_falses to use the checked value (len_u32)
when building (0..len_u32) so no silent truncation occurs.

Comment on lines +128 to +149
let result: Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>> =
if let Some(is_empty) = is_empty {
if *is_empty {
// Return points that don't have values
Some(Box::new(has_values_flags.iter_falses().chain({
let end = has_values_flags.len() as PointOffsetType;
end..total_point_count as u32
})))
} else {
// Return points that have values
Some(Box::new(has_values_flags.iter_trues()))
}
} else if let Some(is_null) = is_null {
if *is_null {
// Return points that have null values
Some(Box::new(is_null_flags.iter_trues()))
} else {
// Return points that don't have null values
Some(Box::new(is_null_flags.iter_falses().chain({
let end = is_null_flags.len() as PointOffsetType;
end..total_point_count as u32
})))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the actual file to verify the code matches the snippet
cat -n lib/segment/src/index/field_index/null_index/shared.rs | sed -n '120,155p'

Repository: qdrant/qdrant

Length of output: 1625


🏁 Script executed:

# Find PointOffsetType definition
rg "type PointOffsetType|PointOffsetType\s*=" --type rs -A 2 | head -20

Repository: qdrant/qdrant

Length of output: 84


🏁 Script executed:

# Check imports and context of the file
head -50 lib/segment/src/index/field_index/null_index/shared.rs

Repository: qdrant/qdrant

Length of output: 2274


🏁 Script executed:

# Find PointOffsetType definition
find . -name "*.rs" -type f | xargs grep -l "type PointOffsetType\|pub.*PointOffsetType" | head -5

Repository: qdrant/qdrant

Length of output: 317


🏁 Script executed:

# Search for PointOffsetType in common module
rg "type PointOffsetType|PointOffsetType\s*=" --max-count 10

Repository: qdrant/qdrant

Length of output: 1067


🏁 Script executed:

# Check if there are other similar patterns with try_from or checked conversions
rg "try_from.*PointOffsetType|PointOffsetType.*try_from" -A 2 -B 2 | head -40

Repository: qdrant/qdrant

Length of output: 968


🏁 Script executed:

# Check how other parts of code handle usize to u32 conversions
rg "as PointOffsetType|as u32" lib/segment/src/index/field_index/ -B 2 -A 2 | head -50

Repository: qdrant/qdrant

Length of output: 4417


🏁 Script executed:

# Check if there are any comments or constraints about maximum point count
rg "PointOffsetType::MAX|u32::MAX" -B 2 -A 2 | head -40

Repository: qdrant/qdrant

Length of output: 3669


🏁 Script executed:

# Check documentation/comments about segment size constraints
rg "segment.*size|max.*point|point.*count" lib/segment/src/ -i -B 1 | grep -A 2 -B 2 "u32\|PointOffsetType" | head -50

Repository: qdrant/qdrant

Length of output: 3843


🏁 Script executed:

# Check if there are invariants or assertions about point count fitting in u32
rg "assert.*point.*count|unwrap|expect.*point" lib/segment/src/index/field_index/ -B 2 -A 1 | head -40

Repository: qdrant/qdrant

Length of output: 3382


🏁 Script executed:

# Look at the context of how total_point_count is set in NullIndexRead implementations
rg "total_point_count\(\)" lib/segment/src/index/field_index/null_index/ -B 5 -A 2

Repository: qdrant/qdrant

Length of output: 2843


🏁 Script executed:

# Check if there are any constraints or documentation about maximum segment size
rg "segment.*capacity|max.*segment|segment.*limit" lib/collection/src/ -i -B 2 -A 2 | head -50

Repository: qdrant/qdrant

Length of output: 4519


🏁 Script executed:

# Look at how segments are created and if there are size limits
rg "create.*segment|new.*segment" lib/collection/src/ -B 2 -A 3 -i | head -60

Repository: qdrant/qdrant

Length of output: 4737


🏁 Script executed:

# Check if there's documentation about PointOffsetType being u32 and any guarantees
rg "PointOffsetType|u32" lib/common/common/src/types.rs -B 5 -A 5

Repository: qdrant/qdrant

Length of output: 962


🏁 Script executed:

# Check if there's more context about segment size constraints
rg "max_segment_size|segment.*capacity" lib/collection/src/config.rs -B 3 -A 3

Repository: qdrant/qdrant

Length of output: 327


🏁 Script executed:

# Look for similar range construction patterns with try_from or checked conversions elsewhere
rg "\.\..*as (u32|PointOffsetType)" lib/segment/src/index/field_index/ -B 2 -A 1

Repository: qdrant/qdrant

Length of output: 4498


Add bounds checking before casting usize to PointOffsetType.

Lines 133, 147-148 cast to u32 without validation. Silent truncation occurs if has_values_flags.len() or total_point_count exceeds u32::MAX, causing the range to incorrectly truncate the tail of the segment.

Suggested fix
+fn to_point_offset(value: usize, what: &'static str) -> PointOffsetType {
+    PointOffsetType::try_from(value).expect(what)
+}
+
 pub(super) fn filter<'a, N: NullIndexRead>(
     idx: &'a N,
     condition: &'a FieldCondition,
 ) -> OperationResult<Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>>> {
@@
                 // Return points that don't have values
                 Some(Box::new(has_values_flags.iter_falses().chain({
-                    let end = has_values_flags.len() as PointOffsetType;
-                    end..total_point_count as u32
+                    let end = to_point_offset(
+                        has_values_flags.len(),
+                        "has_values length must fit into PointOffsetType",
+                    );
+                    end..to_point_offset(
+                        total_point_count,
+                        "total_point_count must fit into PointOffsetType",
+                    )
                 })))
@@
                 // Return points that don't have null values
                 Some(Box::new(is_null_flags.iter_falses().chain({
-                    let end = is_null_flags.len() as PointOffsetType;
-                    end..total_point_count as u32
+                    let end = to_point_offset(
+                        is_null_flags.len(),
+                        "is_null length must fit into PointOffsetType",
+                    );
+                    end..to_point_offset(
+                        total_point_count,
+                        "total_point_count must fit into PointOffsetType",
+                    )
                 })))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let result: Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>> =
if let Some(is_empty) = is_empty {
if *is_empty {
// Return points that don't have values
Some(Box::new(has_values_flags.iter_falses().chain({
let end = has_values_flags.len() as PointOffsetType;
end..total_point_count as u32
})))
} else {
// Return points that have values
Some(Box::new(has_values_flags.iter_trues()))
}
} else if let Some(is_null) = is_null {
if *is_null {
// Return points that have null values
Some(Box::new(is_null_flags.iter_trues()))
} else {
// Return points that don't have null values
Some(Box::new(is_null_flags.iter_falses().chain({
let end = is_null_flags.len() as PointOffsetType;
end..total_point_count as u32
})))
fn to_point_offset(value: usize, what: &'static str) -> PointOffsetType {
PointOffsetType::try_from(value).expect(what)
}
pub(super) fn filter<'a, N: NullIndexRead>(
idx: &'a N,
condition: &'a FieldCondition,
) -> OperationResult<Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>>> {
let result: Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>> =
if let Some(is_empty) = is_empty {
if *is_empty {
// Return points that don't have values
Some(Box::new(has_values_flags.iter_falses().chain({
let end = to_point_offset(
has_values_flags.len(),
"has_values length must fit into PointOffsetType",
);
end..to_point_offset(
total_point_count,
"total_point_count must fit into PointOffsetType",
)
})))
} else {
// Return points that have values
Some(Box::new(has_values_flags.iter_trues()))
}
} else if let Some(is_null) = is_null {
if *is_null {
// Return points that have null values
Some(Box::new(is_null_flags.iter_trues()))
} else {
// Return points that don't have null values
Some(Box::new(is_null_flags.iter_falses().chain({
let end = to_point_offset(
is_null_flags.len(),
"is_null length must fit into PointOffsetType",
);
end..to_point_offset(
total_point_count,
"total_point_count must fit into PointOffsetType",
)
})))
}
} else {
None
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/segment/src/index/field_index/null_index/shared.rs` around lines 128 -
149, The code casts has_values_flags.len(), is_null_flags.len(), and
total_point_count to PointOffsetType (u32) without checking for overflow; add
explicit checked conversions (e.g., PointOffsetType::try_from(...) or
usize::try_into()) for the values used in the range expressions in shared.rs so
overflows are detected before casting, and propagate/handle the error (return an
Err or a safe fallback iterator) instead of silently truncating; update the two
range constructions that use end..total_point_count as PointOffsetType and any
uses of end = ... as PointOffsetType to use the checked conversion and
appropriate error handling.

@qdrant qdrant deleted a comment from coderabbitai Bot May 12, 2026
@timvisee timvisee changed the title fefactor: read only nullindex refactor: read only nullindex May 12, 2026
@coderabbitai

coderabbitai Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds RoaringFlagsRead and NullIndexRead traits to centralize read-only flag and null-index APIs, exposes a few dynamic-stored flag constants/helpers as pub(super), implements ReadOnlyRoaringFlags and ReadOnlyNullIndex that load persisted roaring bitmaps into memory, moves shared null-index query logic into read_ops free functions (filter, estimate_cardinality, condition_checker), and refactors mutable/immutable null index types to implement and delegate through the new read traits.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • qdrant/qdrant#8893: Modifies the same dynamic_stored_flags.rs file, changing visibility and public API of DynamicFlagsStatus and constants.
  • qdrant/qdrant#8961: Also changes dynamic_stored_flags.rs with trait/bounds/impl adjustments overlapping visibility and API surface.
  • qdrant/qdrant#8760: Related work on the flags subsystem and roaring_flags API surface that overlaps the read-only trait refactor.

Suggested reviewers

  • ffuugoo
  • xzfc
  • generall
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only contains the contributor checklist template with no meaningful explanation of the actual changes, rationale, or implementation details related to the read-only null index refactoring. Add a substantive description explaining what the read-only null index refactoring accomplishes, why these changes improve the codebase, and any migration notes for users of affected APIs.
Docstring Coverage ⚠️ Warning Docstring coverage is 24.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor: read only nullindex' is directly related to the changeset, which introduces a read-only null index abstraction and refactors the null index system to use trait-based access patterns.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/read-only-nullindex

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/segment/src/index/field_index/null_index/read_ops.rs`:
- Around line 132-133: The range creation uses unchecked casts from usize to
PointOffsetType (u32) for values like has_values_flags.len(),
is_null_flags.len(), and total_point_count which can truncate; before
constructing ranges in read_ops.rs (the code that computes end =
has_values_flags.len() as PointOffsetType and similar lines), validate that each
usize value is <= PointOffsetType::MAX and return or propagate an error (or
panic with a clear message) if it isn't, otherwise safely cast to
PointOffsetType; reference the has_values_flags, is_null_flags,
total_point_count variables and the PointOffsetType type when adding the guard.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1dd296a6-5f5e-44d8-8187-1de4577d2ff3

📥 Commits

Reviewing files that changed from the base of the PR and between 2ba7b14 and 81c94d2.

📒 Files selected for processing (3)
  • lib/segment/src/common/flags/read_only_roaring_flags.rs
  • lib/segment/src/index/field_index/null_index/read_only_null_index.rs
  • lib/segment/src/index/field_index/null_index/read_ops.rs

Comment on lines +132 to +133
let end = has_values_flags.len() as PointOffsetType;
end..total_point_count as u32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify where usize->PointOffsetType/u32 casts are used and whether bounds are asserted nearby.
rg -nP 'as\s+PointOffsetType|as\s+u32' lib/segment/src/index/field_index/null_index/read_ops.rs
rg -nP 'total_point_count|PointOffsetType::MAX|u32::MAX|try_from\(' lib/segment/src/index/field_index/null_index/*.rs

Repository: qdrant/qdrant

Length of output: 4767


🏁 Script executed:

#!/bin/bash
# Get the definition of PointOffsetType
rg -n 'type PointOffsetType|PointOffsetType =' lib/segment/src/ | head -20

# Get full context of the filter function
sed -n '108,155p' lib/segment/src/index/field_index/null_index/read_ops.rs

# Check if there are any guards or assertions around total_point_count
sed -n '120,135p' lib/segment/src/index/field_index/null_index/read_ops.rs
sed -n '140,150p' lib/segment/src/index/field_index/null_index/read_ops.rs

Repository: qdrant/qdrant

Length of output: 3424


🏁 Script executed:

#!/bin/bash
# Search for PointOffsetType type definition in the entire codebase
rg -n 'type PointOffsetType|^pub.*type PointOffsetType' --type rs lib/

# Also check imports to see where PointOffsetType comes from
rg -n 'use.*PointOffsetType|PointOffsetType' lib/segment/src/index/field_index/null_index/read_ops.rs | head -5

Repository: qdrant/qdrant

Length of output: 396


🏁 Script executed:

#!/bin/bash
# Find PointOffsetType definition in common module
find . -type f -name "*.rs" | xargs grep -l 'type PointOffsetType' 2>/dev/null | head -5

# Direct search without -t flag
rg 'type PointOffsetType' --max-count 5

Repository: qdrant/qdrant

Length of output: 153


🏁 Script executed:

#!/bin/bash
# Check if there are segment size limits documented or enforced
rg -i 'segment.*size|max.*point|point.*limit' lib/segment/src/ --max-count 10

# Check if total_point_count is ever validated
rg 'total_point_count.*>' lib/segment/src/index/field_index/null_index/

Repository: qdrant/qdrant

Length of output: 19595


Guard usize → PointOffsetType casts before building iterator ranges.

Lines 132–133 and 146–147 cast usize values to PointOffsetType (which is u32) without bounds checking. If has_values_flags.len(), is_null_flags.len(), or total_point_count exceed u32::MAX, the casts silently truncate, returning incorrect point IDs.

Proposed fix
-                let end = has_values_flags.len() as PointOffsetType;
-                end..total_point_count as u32
+                let end = PointOffsetType::try_from(has_values_flags.len())
+                    .expect("has_values_flags length exceeds PointOffsetType::MAX");
+                let total = PointOffsetType::try_from(total_point_count)
+                    .expect("total_point_count exceeds PointOffsetType::MAX");
+                end..total
@@
-                let end = is_null_flags.len() as PointOffsetType;
-                end..total_point_count as u32
+                let end = PointOffsetType::try_from(is_null_flags.len())
+                    .expect("is_null_flags length exceeds PointOffsetType::MAX");
+                let total = PointOffsetType::try_from(total_point_count)
+                    .expect("total_point_count exceeds PointOffsetType::MAX");
+                end..total
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let end = has_values_flags.len() as PointOffsetType;
end..total_point_count as u32
let end = PointOffsetType::try_from(has_values_flags.len())
.expect("has_values_flags length exceeds PointOffsetType::MAX");
let total = PointOffsetType::try_from(total_point_count)
.expect("total_point_count exceeds PointOffsetType::MAX");
end..total
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/segment/src/index/field_index/null_index/read_ops.rs` around lines 132 -
133, The range creation uses unchecked casts from usize to PointOffsetType (u32)
for values like has_values_flags.len(), is_null_flags.len(), and
total_point_count which can truncate; before constructing ranges in read_ops.rs
(the code that computes end = has_values_flags.len() as PointOffsetType and
similar lines), validate that each usize value is <= PointOffsetType::MAX and
return or propagate an error (or panic with a clear message) if it isn't,
otherwise safely cast to PointOffsetType; reference the has_values_flags,
is_null_flags, total_point_count variables and the PointOffsetType type when
adding the guard.

@dancixx
dancixx merged commit 816bc78 into dev May 12, 2026
15 checks passed
@dancixx
dancixx deleted the refactor/read-only-nullindex branch May 12, 2026 15:38
@coderabbitai coderabbitai Bot mentioned this pull request May 14, 2026
6 of 9 tasks
generall added a commit that referenced this pull request May 22, 2026
* feat: add read only null index

* fix: linter

* chore: remove unused impl

* chore: revert impl deletion

* fix: linter errors and rename shared->read_ops

* fix: linter

* review fixes

---------

Co-authored-by: generall <[email protected]>
@generall generall added this to the Live-reload milestone May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants