Skip to content

fix(builtins): preserve raw bytes from /dev/urandom through pipeline#870

Merged
chaliy merged 2 commits intomainfrom
fix/issue-811-urandom-raw-bytes
Mar 27, 2026
Merged

fix(builtins): preserve raw bytes from /dev/urandom through pipeline#870
chaliy merged 2 commits intomainfrom
fix/issue-811-urandom-raw-bytes

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 27, 2026

Summary

  • read_text_file: encode /dev/urandom bytes as Latin-1 (each byte 0x00-0xFF maps to one char) instead of UTF-8 lossy conversion
  • head -c: use char-level truncation so Latin-1 encoded bytes are counted correctly
  • tr -c/-C: expand complement set to full 0-255 range so non-ASCII bytes are properly filtered

Makes tr -dc 'a-z0-9' < /dev/urandom | head -c N produce exactly N alphanumeric characters.

Closes #811

Test plan

  • urandom_no_replacement_chars — no UTF-8 replacement chars in output
  • urandom_head_char_counthead -c N produces exactly N chars
  • urandom_tr_filter_alphanumerictr -dc 'a-z0-9' produces clean alphanumeric output
  • Full test suite passes (2111+ tests)
  • cargo fmt and cargo clippy clean

Three fixes for binary data handling:

1. read_text_file: encode /dev/urandom bytes as Latin-1 (each byte 0x00-0xFF
   maps to one char) instead of UTF-8 lossy conversion
2. head -c: use char-level truncation so Latin-1 encoded bytes are counted
   correctly (each char = one original byte)
3. tr -c/-C: expand complement set to full 0-255 range so non-ASCII bytes
   from /dev/urandom are properly filtered

This makes `tr -dc 'a-z0-9' < /dev/urandom | head -c N` produce exactly
N alphanumeric characters.

Closes #811
@chaliy chaliy force-pushed the fix/issue-811-urandom-raw-bytes branch from af1364b to f7a9edd Compare March 27, 2026 17:52
Add exemptions for cmake 0.1.57, console 0.15.11, insta 1.46.3,
simd-adler32 0.3.8, and unicode-segmentation 1.13.1 alongside the
existing exemptions for their newer versions.

These older versions are in Cargo.lock and need exemptions for
cargo-vet to pass in CI.
@chaliy chaliy force-pushed the fix/issue-811-urandom-raw-bytes branch from 36b05fd to 7f60812 Compare March 27, 2026 20:40
@chaliy chaliy merged commit da760af into main Mar 27, 2026
23 checks passed
@chaliy chaliy deleted the fix/issue-811-urandom-raw-bytes branch March 27, 2026 20:48
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.

bug: /dev/urandom returns UTF-8 replacement chars instead of raw bytes

1 participant