rhg: demonstrate a bug in path_encode
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Thu, 16 Feb 2023 14:54:34 +0000
changeset 50147 362fe34702d5
parent 50146 1cffc156f7cd
child 50148 06659dea51b0
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.
rust/hg-core/src/revlog/path_encode.rs
--- 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)
+        );
+    }
+}