-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suspicious comparison at lfs_dir_find_match()
#923
Comments
Oh wow, looks like you're right. Wild that this hasn't been caught until now. I guess it helped that the fact that littlefs's directories are sorted hasn't been the best documented. Other filesystems may have wildly different orderings. We're also lucky none of littlefs's internals currently require sorted order. Otherwise we'd probably be stuck with this weird ordering for backwards compatibility reasons... |
Went ahead and created a PR here: #926 Thanks for reporting! |
Are you sure it's still safe to change the sorting algorithm? From what I understand, on the existing filesystems files are already sorted on disk according to the old algorithm, and even after the fix they'll remain sorted according to it, and further files operations will lead to mixing when old files will remain sorted according to the old algorithm, while new and newly modified files will be sorted according to the new algorithm. Cannot it lead to some nasty bugs like inability to find an existing file because of wrong sorting (if it's taken into account during search). But if currently littlefs doesn't require sorted order at all, won't implementing such a feature lead to breaking the old filesystems where the incorrect ordering of at least some files persists. |
As an option - apply the fix to the next major version, and fix the ordering of existing files through a migration process. |
This is a valid concern. This change definitely deserves caution. I was also too cavalier earlier. I thought fixing this would not be a problem since littlefs does not rely on ordering internally, ordering is more a convenience provided to users. But further investigation indicates this will be a problem a problem with the code as-is as we do rely on ordering for early loop termination[1]. It may still be possible to fix this on a disk-minor-version[2]:
I realized after writing this that I think this is basically the "migration process" you mentioned. I guess the question is, is this worth it? This may end up needing more user feedback.
|
OK. I think the fix should be postponed to the next major disk version, and be applied together with them. |
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation matches the ordering that will be observed when iterating, as described in littlefs-project/littlefs#923
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation matches the ordering that will be observed when iterating, as described in littlefs-project/littlefs#923
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation matches the ordering that will be observed when iterating, as described in littlefs-project/littlefs#923
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923 The fact that directories are ordered is documented: https://github.com/littlefs-project/littlefs/blob/f53a0cc961a8acac85f868b431d2f3e58e447ba3/SPEC.md?plain=1#L304
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923 The fact that directories are ordered is documented: https://github.com/littlefs-project/littlefs/blob/f53a0cc961a8acac85f868b431d2f3e58e447ba3/SPEC.md?plain=1#L304
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923 The fact that directories are ordered is documented: https://github.com/littlefs-project/littlefs/blob/f53a0cc961a8acac85f868b431d2f3e58e447ba3/SPEC.md?plain=1#L304
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923 The fact that directories are ordered is documented: https://github.com/littlefs-project/littlefs/blob/f53a0cc961a8acac85f868b431d2f3e58e447ba3/SPEC.md?plain=1#L304
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923 The fact that directories are ordered is documented: https://github.com/littlefs-project/littlefs/blob/f53a0cc961a8acac85f868b431d2f3e58e447ba3/SPEC.md?plain=1#L304
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923 The fact that directories are ordered is documented: https://github.com/littlefs-project/littlefs/blob/f53a0cc961a8acac85f868b431d2f3e58e447ba3/SPEC.md?plain=1#L304
The ordering of path (as obtained when iterating over a directory) in Littlefs is not exactly what is expected. This implementation contains 2 comparision functions, one matching what is expected, and one matching the iteration order of littlefs directories, as described in littlefs-project/littlefs#923 The fact that directories are ordered is documented: https://github.com/littlefs-project/littlefs/blob/f53a0cc961a8acac85f868b431d2f3e58e447ba3/SPEC.md?plain=1#L304
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
… `not_before` In fido-authenticator, if we change the paths of RK to be: "rp_id.rk_id" instead of the current "rp_id/rk_id", we still want to be able to iterate over the keys even though we only know the "rp_id" and not the "rk_id". Therefore we need to be able to stop at "rp_id.***" when giving "rp_id" in `not_before` This is technically a breaking change because now, given the files: - "aaa" - "aaabbb" "read_dir_first" with "aaa" as `not_before` would only yield "aaa" due to littlefs-project/littlefs#923. Now this will yield both files, and yield "aaabbb" first. I beleive this behaviour is technically more correct as it is likely what would be expected to be yield expecting alphabetical order (though the order of the entries is still incorrect).
The function uses
lfs_bd_cmp()
which, from what I understand, compares data on disk with an arbitrary data passed as argument, and returns:LFS_CMP_LT
- the data on disk is less than the arbitrary dataLFS_CMP_GT
- the data on disk is greater than the arbitrary dataLFS_CMP_EQ
- the data on disk and the arbitrary data are equalIf the function returns
LFS_CMP_EQ
, we perform an additional comparison:This comparison looks suspicious because it returns
LFS_CMP_LT
is the arbitrary data (not the data on disk) is shorter than the data on disk. Maybe it was intended this way but just in case decided to report.The text was updated successfully, but these errors were encountered: