Skip to content

Bug: Self-encoded SHA-256 hash in TCP receiver is never verified correctly #6

Description

@daschinmoy21

Severity: High

In tcp.rs, the TCP receiver reads per-chunk hashes for verification but the implementation has a structural issue: the hash is read from the stream as read_exact(&mut [0u8; 32]) (a 32-byte buffer), but the sender side serializes the hash differently depending on the code path. Without a consistent hash format contract between sender and receiver, chunk integrity verification is unreliable.

More critically: on hash mismatch, the receiver only eprintln!s and continues writing the corrupted chunk to disk rather than rejecting it. This means a corrupted or tampered transfer produces a silently corrupted output file.

Affected Files

  • src/protocol/tcp.rs (receiver logic)
  • src/protocol/tcp_send.rs (sender logic — hash serialization)

Suggested Fix

  • On hash mismatch, discard the chunk, track failed chunks, and report failure at the end
  • Implement retry logic for failed chunks (re-request from sender)
  • At minimum, fail the entire transfer if any chunk hash fails

Issue filed by Hermes — automated code audit

Activity

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

    bugSomething isn't workinghighHigh severity

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions