From: Tim Kientzle Date: Sat, 3 Sep 2011 18:22:57 +0000 (-0400) Subject: Test integer parsing at the limits of 64-bit integers. X-Git-Tag: v3.0.0a~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56dec820a9c76efb3f6bf4e7f30b2ce3957a20e9;p=thirdparty%2Flibarchive.git Test integer parsing at the limits of 64-bit integers. SVN-Revision: 3672 --- diff --git a/libarchive/test/test_read_format_mtree.c b/libarchive/test/test_read_format_mtree.c index 1f39e27d1..1d2e84152 100644 --- a/libarchive/test/test_read_format_mtree.c +++ b/libarchive/test/test_read_format_mtree.c @@ -33,6 +33,11 @@ test_read_format_mtree1(void) struct archive_entry *ae; struct archive *a; FILE *f; + // Compute min and max 64-bit signed twos-complement values + // without relying on overflow. This assumes that long long + // is at least 64 bits. + const static long long max_int64 = ((((long long)1) << 62) - 1) + (((long long)1) << 62); + const static long long min_int64 = - (((long long)1) << 62) - (((long long)1) << 62); extract_reference_file(reffile); @@ -104,8 +109,32 @@ test_read_format_mtree1(void) assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "notindir"); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/emptyfile"); + assertEqualInt(archive_entry_size(ae), 0); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/smallfile"); + assertEqualInt(archive_entry_size(ae), 1); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/bigfile"); + assertEqualInt(archive_entry_size(ae), max_int64); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/toobigfile"); + assertEqualInt(archive_entry_size(ae), max_int64); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/veryoldfile"); + assertEqualInt(archive_entry_mtime(ae), min_int64); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/toooldfile"); + assertEqualInt(archive_entry_mtime(ae), min_int64); + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(12, archive_file_count(a)); + assertEqualInt(18, archive_file_count(a)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); } diff --git a/libarchive/test/test_read_format_mtree.mtree.uu b/libarchive/test/test_read_format_mtree.mtree.uu index 1634d0015..993875fe7 100644 --- a/libarchive/test/test_read_format_mtree.mtree.uu +++ b/libarchive/test/test_read_format_mtree.mtree.uu @@ -1,5 +1,3 @@ -$FreeBSD: head/lib/libarchive/test/test_read_format_mtree.mtree.uu 201247 2009-12-30 05:59:21Z kientzle $ - begin 644 test_read_format_mtree.mtree M(VUT7!E/61I<@H@9FEL95PP-#!W:71H7#`T,'-P86-E('1Y<&4]9FEL @@ -8,6 +6,13 @@ M9&ER,B!T>7!E/61I<@H@9&ER,V$@='EP93UD:7(*("!I;F1I7!E/61I<@H@(&EN9&ER,V(@ M='EP93UF:6QE"B`@+BX*("XN"FYO=&EN9&ER('1Y<&4]9FEL90ID:7(R+V9U -3;&QI;F1I7!E/69I;&4@7!E/69I;&4@=&EM93TM.3(R,S,W,C`S-C@U-#