ForensicRS / frnsc-prefetch

Pure rust windows prefetch parser implementation
MIT License
3 stars 2 forks source link

Panic on rust version 1.81 #4

Closed puffyCid closed 1 month ago

puffyCid commented 1 month ago

:wave: Hello @SecSamDev , I wanted to open a small issue I recently encountered while using parts of this library. Specifically the huffman decompression code.

I am using the decompression code to help decompress Prefetch files.

Recently the sorting algorithm in Rust trait Ord changed in Rust version 1.81, as mentioned in the release notes.

Code that uses the Ord and PartialOrd traits now need to implement a total order sort otherwise Rust will panic with the message: user-provided comparison function does not correctly implement a total order.

I was able to review and believe the issue is at:

symbol_info.sort_by(|a, b| {
        if a.length < b.length {
            return Ordering::Less;
        }

        if a.symbol < b.symbol {
            return Ordering::Less;
        }
        Ordering::Equal
    });

It looks like starting in version 1.81 both greater and less than comparisons need to be used. The code below no longer panics.

symbol_info.sort_by(|a, b| {
        if a.length < b.length {
            return Ordering::Less;
        }
        if a.length > b.length {
            return Ordering::Greater;
        }

        if a.symbol < b.symbol {
            return Ordering::Less;
        }
        if a.symbol > b.symbol {
            return Ordering::Greater;
        }
        Ordering::Equal
    });

I can open a PR for the fix if you would like, otherwise will defer to you if you want to fix.

Thanks again for the awesome library!

SecSamDev commented 1 month ago

Thanks for reporting. Feel free to make the pull request.

SecSamDev commented 1 month ago

Merged! Publishing new version