Skip to content

[pointer] Fix bug in try_cast_into_no_leftover#2937

Merged
joshlf merged 1 commit intomainfrom
G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a
Jan 29, 2026
Merged

[pointer] Fix bug in try_cast_into_no_leftover#2937
joshlf merged 1 commit intomainfrom
G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Jan 27, 2026

Previously, Ptr::try_cast_into_no_leftover used the following logic to
recover the original Ptr in the case of failure:

match self.try_cast_into(CastType::Prefix, meta) {
    Ok((slf, remainder)) => {
        if remainder.len() == 0 {
            Ok(slf)
        } else {
            // Undo the cast so we can return the original bytes.
            let slf = slf.as_bytes();

This is incorrect: In the case that remainder.len() > 0, slf no
longer refers to the same referent as it did originally, as there are
remainder bytes (either in the prefix or the suffix). In this commit, we
use Ptr::try_with to restore the original Ptr exactly.


Latest Update: v23 — Compare vs v22

📚 Full Patch History

Links show the diff between the row version and the column version.

Version v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v8 v7 v6 v5 v4 v3 v2 v1 Base
v7 v6 v5 v4 v3 v2 v1 Base
v6 v5 v4 v3 v2 v1 Base
v5 v4 v3 v2 v1 Base
v4 v3 v2 v1 Base
v3 v2 v1 Base
v2 v1 Base
v1 Base

Stacked PRs enabled by GHerrit.

@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.29%. Comparing base (d161a87) to head (d3359ba).

Files with missing lines Patch % Lines
src/pointer/ptr.rs 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2937      +/-   ##
==========================================
+ Coverage   92.21%   92.29%   +0.07%     
==========================================
  Files          19       19              
  Lines        5860     5868       +8     
==========================================
+ Hits         5404     5416      +12     
+ Misses        456      452       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch from f0fa851 to 71f7209 Compare January 28, 2026 17:19
@joshlf joshlf changed the base branch from main to G7f73f342a0126d5f9b9dc44925f6ae7451034bef January 28, 2026 17:19
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch from 4f7ace4 to c75ac98 Compare January 28, 2026 18:14
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch from 71f7209 to 04b7eed Compare January 28, 2026 18:14
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch from c75ac98 to 9c4c755 Compare January 28, 2026 18:26
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch 2 times, most recently from 7f5c72a to 71c76fb Compare January 28, 2026 21:06
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch from 9c4c755 to ca91310 Compare January 28, 2026 21:06
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch 2 times, most recently from d749a54 to 2555a94 Compare January 28, 2026 21:15
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch from ca91310 to 62ba5db Compare January 28, 2026 21:56
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch from 2555a94 to 4029dea Compare January 28, 2026 21:56
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch from 62ba5db to d21e64f Compare January 28, 2026 21:57
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch 2 times, most recently from b0fa89d to 0b725a6 Compare January 29, 2026 03:06
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch 2 times, most recently from a251055 to 9b6af27 Compare January 29, 2026 14:07
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch from 0b725a6 to 0752d5f Compare January 29, 2026 14:07
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch from 9b6af27 to c5c6edd Compare January 29, 2026 16:05
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch from 0752d5f to 3d46f9f Compare January 29, 2026 16:05
@joshlf joshlf force-pushed the G7f73f342a0126d5f9b9dc44925f6ae7451034bef branch from c5c6edd to f6656e5 Compare January 29, 2026 16:08
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch 2 times, most recently from f442a98 to 04486ac Compare January 29, 2026 16:13
Base automatically changed from G7f73f342a0126d5f9b9dc44925f6ae7451034bef to main January 29, 2026 16:42
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch from 04486ac to 49aafa2 Compare January 29, 2026 16:42
@joshlf joshlf enabled auto-merge January 29, 2026 16:42
@joshlf joshlf added this pull request to the merge queue Jan 29, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 29, 2026
Previously, `Ptr::try_cast_into_no_leftover` used the following logic to
recover the original `Ptr` in the case of failure:

```rust
match self.try_cast_into(CastType::Prefix, meta) {
    Ok((slf, remainder)) => {
        if remainder.len() == 0 {
            Ok(slf)
        } else {
            // Undo the cast so we can return the original bytes.
            let slf = slf.as_bytes();
```

This is incorrect: In the case that `remainder.len() > 0`, `slf` no
longer refers to the same referent as it did originally, as there are
remainder bytes (either in the prefix or the suffix). In this commit, we
use `Ptr::try_with` to restore the original `Ptr` exactly.

gherrit-pr-id: G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a
@joshlf joshlf force-pushed the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch from 49aafa2 to d3359ba Compare January 29, 2026 17:30
@joshlf joshlf enabled auto-merge January 29, 2026 17:30
@joshlf joshlf added this pull request to the merge queue Jan 29, 2026
Merged via the queue into main with commit a5aa985 Jan 29, 2026
104 checks passed
@joshlf joshlf deleted the G27c254ea62bb8b789e4fcd4a2e9e09a74676b45a branch January 29, 2026 18:05
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.

3 participants