]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
time: Use archive_integer.h 3134/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 10 Jun 2026 18:09:24 +0000 (20:09 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 12 Jun 2026 21:32:41 +0000 (23:32 +0200)
Use archive_integer's checked integer arithmetic.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_time.c

index 0f02345f37cbd504ab12fffe7891e4cf9ef07855..bc77082889760d4e9f8826b3e011aaa1e1deb828 100644 (file)
@@ -35,6 +35,7 @@
 #include <string.h>
 #endif
 
+#include "archive_integer.h"
 #include "archive_private.h"
 #include "archive_time_private.h"
 
@@ -157,15 +158,11 @@ unix_to_ntfs(int64_t secs, uint32_t nsecs)
        if (secs < -(int64_t)NTFS_EPOC_TIME)
                return 0;
 
-       ntfs = secs + NTFS_EPOC_TIME;
-
-       if (ntfs > UINT64_MAX / NTFS_TICKS)
-               return UINT64_MAX;
-
-       ntfs *= NTFS_TICKS;
-
-       if (ntfs > UINT64_MAX - nsecs/100)
+       /* (secs + NTFS_EPOC_TIME) * NTFS_TICKS + nsecs / 100 */
+       if (archive_ckd_add_u64(&ntfs, secs, NTFS_EPOC_TIME) ||
+           archive_ckd_mul_u64(&ntfs, ntfs, NTFS_TICKS) ||
+           archive_ckd_add_u64(&ntfs, ntfs, nsecs / 100))
                return UINT64_MAX;
 
-       return ntfs + nsecs/100;
+       return ntfs;
 }