littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
4.9k stars 771 forks source link

Fix name ordering when names only differ in length #926

Open geky opened 5 months ago

geky commented 5 months ago

Wild this hasn't been caught until now.

Because the exact ordering of the comparison in lfs_bd_cmp is a bit ambiguous, lfs_dir_find_match returned the wrong result when filenames were equal, and only differed in length.

For example:

We're quite lucky that none of the littlefs internals currently depend on the sorted order, otherwise we'd probably be stuck with this weird ordering for backwards compatibility reasons...

Fixed, and added some test cases over directory ordering to prevent regression in the future.

Found by @andriyndev Related issue https://github.com/littlefs-project/littlefs/issues/923

geky-bot commented 5 months ago
Tests passed ✓, Code: 16828 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 800 B (+0.0%) | | Code | Stack | Structs | | Coverage | |:--|-----:|------:|--------:|:--|---------:| | Default | 16828 B (+0.0%) | 1448 B (+0.0%) | 800 B (+0.0%) | Lines | 2357/2533 lines (+0.0%) | | Readonly | 6130 B (+0.0%) | 448 B (+0.0%) | 800 B (+0.0%) | Branches | 1202/1528 branches (+0.0%) | | Threadsafe | 17696 B (+0.0%) | 1448 B (+0.0%) | 808 B (+0.0%) | | **Benchmarks** | | Multiversion | 16892 B (+0.0%) | 1448 B (+0.0%) | 804 B (+0.0%) | Readed | 29369693876 B (+0.0%) | | Migrate | 18508 B (+0.0%) | 1752 B (+0.0%) | 804 B (+0.0%) | Proged | 1482874766 B (+0.0%) | | Error-asserts | 17484 B (+0.0%) | 1440 B (+0.0%) | 800 B (+0.0%) | Erased | 1568888832 B (+0.0%) |