changeset 50095:362fe34702d5

rhg: demonstrate a bug in path_encode The bug means that long filenames at the root of the tree are encoded incorrectly by rhg, so rhg crashes when trying to access them.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 16 Feb 2023 14:54:34 +0000
parents 1cffc156f7cd
children 06659dea51b0
files rust/hg-core/src/revlog/path_encode.rs
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 14:43:46 2023 +0000
+++ b/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 14:54:34 2023 +0000
@@ -643,3 +643,22 @@
         hash_encode(path)
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::utils::hg_path::HgPathBuf;
+
+    // expected failure
+    #[test]
+    #[should_panic]
+    fn test_long_filename_at_root() {
+        let input = b"data/ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ.i";
+        let expected = b"dh/abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij.i708243a2237a7afae259ea3545a72a2ef11c247b.i";
+        let res = path_encode(input);
+        assert_eq!(
+            HgPathBuf::from_bytes(&res),
+            HgPathBuf::from_bytes(expected)
+        );
+    }
+}