Skip to content

Fix three implementation bugs found during codebase audit#3

Merged
tmthecoder merged 1 commit intomainfrom
fix-some-impl-bugs
Feb 8, 2026
Merged

Fix three implementation bugs found during codebase audit#3
tmthecoder merged 1 commit intomainfrom
fix-some-impl-bugs

Conversation

@tmthecoder
Copy link
Copy Markdown
Owner

Summary

Fixes three correctness bugs discovered during a deep codebase audit against the Rust Book and MS-SMB2 spec.


Bug Fixes

B1: byte_helper.rs — u64 bit shift uses 54 instead of 56 (data corruption)

File: smb/src/byte_helper.rs

Problem: Both bytes_to_u64 and u64_to_bytes use bit shift 54 for the high byte (index 7) instead of the correct 56 (7 × 8 = 56). This follows the pattern 0, 8, 16, 24, 32, 40, 48, **54** where the last value should be 56.

This is a data corruption bug — any u64 value with significant bits above position 53 will be silently mangled during serialization or deserialization. It has not manifested in integration tests because the only call sites (FileTime and SMBExtra) currently operate on values small enough that the top byte is zero or trivially small. However, it will break for large file sizes, far-future timestamps, or any u64 field where the top byte is non-trivial.

Fix: Changed << 54 to << 56 and >> 54 to >> 56 in both functions.

Tests: The existing u64_max_value_round_trip and u64_high_bits_correctness tests (which were previously documenting the bug) now pass.


B2: SMBServerError::Display says "Parse failed" instead of "Server operation failed"

File: smb-core/src/error.rs

Problem: The Display impl for SMBServerError printed "Parse failed with error: ..." which is copy-pasted from SMBParseError. This is misleading — a server error is not a parse error.

Fix: Changed the prefix to "Server operation failed with error: ...".

Tests: Added 5 new tests covering the Display output of all error variants (SMBServerError, SMBParseError, SMBCryptoError, SMBPayloadSizeError, SMBResponseError) to prevent future regressions.


B3: SMBDialect::V3_0_2 missing from signing key KDF derivation branch

File: smb/src/server/session.rs

Problem: In generate_keys(), the match arm for KDF-derived signing keys only covered V3_0_0 | V3_1_1. V3_0_2 fell through to the _ wildcard, which returns the raw session key without KDF derivation. Per [MS-SMB2] Section 3.3.5.5.3, all SMB 3.x dialects (3.0, 3.0.2, 3.1.1) must derive signing keys using SP800-108 KDF.

Fix: Added SMBDialect::V3_0_2 to the KDF match arm.

Tests: Added 3 new tests verifying that generate_key produces correct-length output, that KDF output differs from the raw session key, and that V3_0_2 and V3_0_0 produce identical signing keys (since they use the same label/context).


Test Results

All 13 tests pass:

  • smb-core: 5 new error Display tests ✅
  • smb_reader::byte_helper: 5 tests (3 existing + 2 previously-failing now fixed) ✅
  • smb_reader::server::session: 3 new KDF tests ✅

B1: Fix u64 bit shift 54 -> 56 in byte_helper.rs
B2: Fix SMBServerError::Display wrong prefix
B3: Add V3_0_2 to signing key KDF derivation branch

Includes regression tests for all three fixes.
@tmthecoder tmthecoder merged commit 0593b54 into main Feb 8, 2026
3 of 5 checks passed
@tmthecoder tmthecoder deleted the fix-some-impl-bugs branch February 8, 2026 21:27
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.

1 participant