Potential soundness issue in `bitpacking` 0.9.3

未关闭
#70 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
rust
领域
security

调研方向

Start with the safe wrappers in src/bitpacker1x.rs:161 and the unsafe implementation in src/macros_simple.rs:424-438. Run the provided short-slice reproducer under Miri, then inspect the corresponding sorted variants. Done means the public sorted APIs reject invalid block lengths or otherwise avoid undefined behavior, with the reproducer no longer reporting the dangling-pointer access.

由索引模型根据 Issue 内容生成。

描述

Hello, and thank you for maintaining this crate.

I found a sanitizer/Miri failure reachable through public crate APIs using safe Rust code. I may be missing crate-specific preconditions, but the behavior looks worth checking because safe callers should not be able to trigger undefined behavior.

Summary

  • Crate: bitpacking
  • Version tested: 0.9.3
  • API paths with similar failures observed:
    • BitPacker1x::num_bits_sorted
    • BitPacker1x::num_bits_strictly_sorted
    • BitPacker4x::num_bits_sorted
    • BitPacker4x::num_bits_strictly_sorted

Observed diagnostics

Miri undefined behavior: error: Undefined Behavior: memory access failed: attempting to access 4 bytes, but got 0x4[noalloc] which is a dangling pointer (it has no provenance)

Reproduction

The snippets below are minimal readable reproducers. Each PoC also includes the source location most relevant to the reported failure.

PoC 1: test_bitpacking3::generated_test_3

Relevant source location:

  • src/bitpacker1x.rs:161: the safe wrapper calls UnsafeBitPackerImpl::num_bits_sorted.
  • src/macros_simple.rs:424-438: the unsafe implementation loads a full fixed block from decompressed.

Readable equivalent PoC:

use bitpacking::{BitPacker, BitPacker1x};

#[test]
fn poc() {
    let packer = BitPacker1x::new();
    let short_block: Vec<u32> = Vec::new();

    let _ = packer.num_bits_sorted(0, &short_block);
}

Observed diagnostic:

error: Undefined Behavior: memory access failed: attempting to access 4 bytes, but got 0x4[noalloc] which is a dangling pointer (it has no provenance)

Source review and suggested fix

Brief reasoning:

  • The public num_bits path already checks for the exact block length.
  • The sorted variants skip that check and still load a full block from the slice.
  • That makes the length precondition caller-visible through a safe API.

Suggested fix:

  • Validate the exact block length before calling the unsafe routine, or make the precondition explicit in an unsafe API.

Thanks again for taking a look.

主要语言
Rust
星标
346
派生
37
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quickwit-oss/bitpacking 的其他 Issue

查看 quickwit-oss/bitpacking 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。