Skip to content

prisma_cmd.rs migration-name slice panics with out-of-bounds index when token is short and line-final #3445

Closed

Description

@albatrossflyon-coder

Split off from #2954 (per @HetCreep's audit at v0.44.2), same session as #3444 — a different failure mode than the byte-boundary family: an out-of-bounds slice rather than a mid-character one.

src/cmds/js/prisma_cmd.rs:319-321:

let end = line[pos..].find(|c: char| c.is_whitespace()).unwrap_or(20);
latest_migration = line[pos..pos + end].to_string();

When the 202… migration token is the last thing on the line (no trailing whitespace to find) and shorter than 20 bytes, .unwrap_or(20) hands back a fixed length that overruns the actual remaining string, and pos + end slices past the end.

Note prisma_cmd.rs:252, ~60 lines earlier in the same file, already has the correct fallback: .unwrap_or(line.len() - pos). Line 319 just didn't get the same fix.

Live repro:

fn prisma_slice(line: &str) -> String {
    let pos = line.find("202").unwrap();
    let end = line[pos..].find(|c: char| c.is_whitespace()).unwrap_or(20);
    line[pos..pos + end].to_string()
}
fn main() {
    let line = "applied 20240115_x"; // token from pos to end-of-line is 11 bytes, no trailing whitespace
    println!("{}", prisma_slice(line));
}
thread 'main' panicked at repro.rs:8:9:
end byte index 28 is out of bounds for string of length 18

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

Suggested fix: mirror line 252's fallback:

let end = line[pos..].find(|c: char| c.is_whitespace()).unwrap_or(line.len() - pos);

(Credit: @HetCreep's source audit on #2954 first flagged 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 medium
    🎯 Confidence 97%

    Summary

    prisma_cmd.rs:319-321 slices with a fixed unwrap_or(20) fallback that overruns short, line-final migration tokens, panicking on out-of-bounds index — fix by mirroring line 252's unwrap_or(line.len() - pos).

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

    📁 Relevant files
    • src/cmds/js/prisma_cmd.rs

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

  3. KuSh commented on Nov 23, 2026

    @KuSh
    Collaborator

    Fixed by #3836, shipped in v0.50.0: the migration id is now sliced to the end of the line instead of a fixed 20 bytes. rtk prisma migrate status on output ending with applied 20240115_x no longer panics. Please reopen or comment if you still see this on the latest release.

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:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions