Преглед на файлове

Fix overflowing UIDs and GIDs

Fixes #26.
Ben S преди 11 години
родител
ревизия
38a785426b
променени са 1 файла, в които са добавени 28 реда и са изтрити 2 реда
  1. 28 2
      src/file.rs

+ 28 - 2
src/file.rs

@@ -263,7 +263,7 @@ impl<'a> File<'a> {
 
         let user_name = match users_cache.get_user_by_uid(uid) {
             Some(user) => user.name,
-            None => uid.to_string(),
+            None => self.stat.unstable.uid.to_string(),
         };
 
         let style = if users_cache.get_current_uid() == uid { Yellow.bold() } else { Plain };
@@ -287,7 +287,7 @@ impl<'a> File<'a> {
                 }
                 group.name
             },
-            None => gid.to_string(),
+            None => self.stat.unstable.gid.to_string(),
         };
 
         Cell::paint(style, &*group_name)
@@ -601,6 +601,19 @@ pub mod test {
             let cell = Cell::paint(Plain, "1000");
             assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
         }
+
+        #[test]
+        fn overflow() {
+            let mut stat = dummy_stat();
+            stat.unstable.uid = 2_147_483_648;
+
+            let file = new_file(stat, "/hi");
+
+            let mut users = MockUsers::with_current_uid(3);
+
+            let cell = Cell::paint(Plain, "2147483648");
+            assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
+        }
     }
 
     mod groups {
@@ -662,5 +675,18 @@ pub mod test {
             let cell = Cell::paint(Yellow.bold(), "folk");
             assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
         }
+
+        #[test]
+        fn overflow() {
+            let mut stat = dummy_stat();
+            stat.unstable.gid = 2_147_483_648;
+
+            let file = new_file(stat, "/hi");
+
+            let mut users = MockUsers::with_current_uid(3);
+
+            let cell = Cell::paint(Plain, "2147483648");
+            assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
+        }
     }
 }