Slice::len returns zero for pool-backed slices

Open Beginner friendly
#2,383 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
networking

Research direction

Start at slice.rs:106-110 and inspect how Slice::len handles owned and pool-backed slices. Trace BufferPool::get_data_owned and binary_sv2's GetSize for Slice to understand the affected path. Done means pool-backed len() returns the stored len and agrees with as_ref().len(), including for non-empty received frames.

Written by the indexing model from the issue text.

Description

Slice::len (slice.rs:106-110) reads the backing Vec only when owned is Some; every pool-backed slice reports zero even though its len field is set and AsRef<[u8]> exposes the whole payload. BufferPool::get_data_owned produces exactly these slices, and binary_sv2's GetSize for Slice forwards to the same method, so a non-empty received frame passes any len() <= limit or is_empty() check as if it had no bytes and is then processed in full through as_ref(). Distinct from #2352, which is get_data_by_ref ignoring its argument.

Fix: return the stored len for pool-backed slices, so len() and as_ref().len() agree in every mode.

Dominant language
Rust
Stars
352
Forks
200
Avg merge
4d 17h
Merged PRs (30d)
12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stratum-mining/stratum

All issues in stratum-mining/stratum

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.