Skip to content

Example in find_chunk_edge() can panic 'range start index' #29

Closed

Description

@allada

Using some example code here:
https://docs.rs/hash-roll/0.3.0/hash_roll/trait.Chunk.html#tymethod.find_chunk_edge

It turns out that discard_ct could result in data.len() + 1 in size as seen in this code:
https://docs.rs/hash-roll/0.3.0/src/hash_roll/fastcdc.rs.html#75

The only happens when the boundary is on the last byte and can result in i equaling data.len() causing &data[..data.len() + 1] resulting in a panic.

The fix is simple, I might suggest adding something like this to the docs:

if discard_ct > data_buf.len() {
    break;
}

Thanks for the hard work in providing this library!

Activity

  1. safinaskar commented on Jun 17, 2023

    @safinaskar

    @jmesmon , example in https://docs.rs/hash-roll/0.3.0/hash_roll/trait.Chunk.html#tymethod.find_chunk_edge seems to be absolutely incorrect. It initializes prev_cut to 0 and then never sets it again. So it seems something is really wrong here. So I'm afraid to use this library, because there is no example I can rely on

  2. safinaskar commented on Jun 17, 2023

    @safinaskar

    Also, it seems that &orig_data[prev_cut..g_cut] instead of &orig_data[prev_cut..cut_point] should be. There may be other bugs in this code, so, please, proof read it

  3. codyps commented on Oct 31, 2026

    @codyps
    Owner

    The FastCDC forced maximum boundary now returns an offset within the supplied buffer, and both APIs use exclusive end offsets. The example also preserves the trailing incomplete chunk. Fixed in ee44de0 and included in #36; regression and fragmented-input tests cover the reported failure. This issue will close when #36 merges. The published 0.3.0 documentation remains unchanged until a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions