bojand / infer

Small crate to infer file and MIME type by checking the magic number signature
MIT License
299 stars 28 forks source link

Fix infinite `while` loop when buf size is less than `3` #80

Closed kailes closed 1 year ago

6xzo commented 2 years ago

If you add these additional cases to the tests, they hang without this fix.

    #[test]
    fn test_get_unknown() {
        let buf = [];
        assert!(crate::get(&buf).is_none());
// new cases:
        let buf = [0x31];
        assert!(crate::get(&buf).is_none());
        let buf = [0x31, 0x32];
        assert!(crate::get(&buf).is_none());
    }
kailes commented 2 years ago

@bojand Hi, have some time to review this?

bojand commented 1 year ago

Hello, thanks for the PR. This should be available in v0.12.0.