Skip to content

truncate_iso_date byte-index slice panics on multi-byte UTF-8 input #3444

Open

Description

@albatrossflyon-coder

Split off from #2954 (per @HetCreep's audit at v0.44.2) — the original Cyrillic panic in gain.rs is fixed, but the same byte-vs-char-boundary shape survives in src/core/utils.rs:

pub fn truncate_iso_date(date: &str) -> &str {
    if date.len() >= 10 { &date[..10] } else { date }
}

date.len() is a byte count; &date[..10] is a byte index. Any string with a multi-byte UTF-8 character before byte offset 10 panics instead of truncating.

Reached from 7 call sites in src/cmds/cloud/aws_cmd.rs (lines 649, 674, 782, 869, 960, 999, 1301), each fed a date field off an AWS-style JSON response — i.e. reachable from real API output, not just adversarial input.

Live repro (standalone, same function body):

fn truncate_iso_date(date: &str) -> &str {
    if date.len() >= 10 { &date[..10] } else { date }
}
fn main() {
    let s = "2024-01-1\u{00e9}5T10:30:00Z"; // é lands byte 9..11
    println!("{}", truncate_iso_date(s));
}
thread 'main' panicked at repro.rs:2:32:
end byte index 10 is not a char boundary; it is inside 'é' (bytes 9..11 of string)

Confirmed exit code 101, matches current develop (3044911).

Suggested fix: same pattern already used correctly elsewhere in-tree — gain.rs:730 and session_cmd.rs:113 both use str::floor_char_boundary. e.g.:

pub fn truncate_iso_date(date: &str) -> &str {
    &date[..date.floor_char_boundary(10)]
}

(Credit: @HetCreep's source audit on #2954 first identified this while confirming the original issue was fixed — filing separately per their suggestion since it's a distinct call site/bug from the original report.)

Activity

  1. added
    bug
    good first issue
    on Aug 5, 2026
  2. pszymkowiak commented on Aug 5, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 97%

    Summary

    byte-index slice in truncate_iso_date (src/core/utils.rs) panics on multi-byte UTF-8 dates reachable from real AWS JSON responses via 7 call sites in aws_cmd.rs; fix with str::floor_char_boundary as already used in gain.rs/session_cmd.rs

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/core/utils.rs
    • src/cmds/cloud/aws_cmd.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

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

    area:clibuggood first issuepriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions