Skip to content

[bug] parse_shebang can return an empty list #925

@feliblo

Description

@feliblo

Summary

I encountered a panic when running against the ardupilot repository in this PR #915

Insrc/identity.rs this line caused prek to panic

    tags.extend(tags_from_filename(path));
    if executable {
        if let Ok(shebang) = parse_shebang(path) {
            tags.extend(tags_from_interpreter(&shebang[0]));
        }
    }

output:

prek run check-executables-have-shebangs --all-files --verbose
thread '<unnamed>' panicked at src/identify.rs:767:55:
index out of bounds: the len is 0 but the index is 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It panics because of illegal access of the first element in what could still be an empty list (&shebang[0]).
I adressed the issue in #915, as well, but only adressed the illegal access, not the parse_shebang function itself.

Platform

Darwin 24.6.0 arm64

Version

v0.2.9

.pre-commit-config.yaml

No response

Log file

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions