diff --git a/.gitattributes b/.gitattributes index e43d01bc9202abccccf53e390c739038a49bf291..e833b22d305a92e2bbd0c1f35d17ca77171e5080 100644 --- a/.gitattributes +++ b/.gitattributes @@ -107,3 +107,10 @@ local-test-tika-delta-05/afc-tika/tika-parsers/tika-parsers-extended/tika-parser local-test-tika-delta-05/fuzz-tooling/infra/cifuzz/test_data/timeout_fuzzer filter=lfs diff=lfs merge=lfs -text local-test-tika-delta-05/afc-tika/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/test/resources/test-documents/testJournalParser.pdf filter=lfs diff=lfs merge=lfs -text local-test-tika-delta-05/afc-tika/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/test/resources/test-documents/test.hdf filter=lfs diff=lfs merge=lfs -text +local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-358.uncompressed filter=lfs diff=lfs merge=lfs -text +local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/testNumbersNew.numbers filter=lfs diff=lfs merge=lfs -text +local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z02 filter=lfs diff=lfs merge=lfs -text +local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/pack200/jars/ant.jar filter=lfs diff=lfs merge=lfs -text +local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z01 filter=lfs diff=lfs merge=lfs -text +local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z01 filter=lfs diff=lfs merge=lfs -text +local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z02 filter=lfs diff=lfs merge=lfs -text diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/7z-empty-mhc-off.7z b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/7z-empty-mhc-off.7z new file mode 100644 index 0000000000000000000000000000000000000000..cf94b29d54ca070979a25dfb1ef103a157411a3f --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/7z-empty-mhc-off.7z @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0450dc9369e4e5e42488d0dc1edce863cf013c5aedcdf231338f270cd314c241 +size 78 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/7z-hello-mhc-off-lzma2.7z b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/7z-hello-mhc-off-lzma2.7z new file mode 100644 index 0000000000000000000000000000000000000000..51114124ecb41e42d2165e4600c9772e8b7d3b53 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/7z-hello-mhc-off-lzma2.7z @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0052f7f4e201f9eab215679cb1e2f2e0b7b0040d826e869302e117eaa5a439fd +size 138 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-114.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-114.tar new file mode 100644 index 0000000000000000000000000000000000000000..9d9257cbe3a6f0ce77069341910e0eb7fec7ae4d --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-114.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:575763c5065f5dc79cf7bc83911668a968c4fc4a1cf7df7038dc16cb90ea7721 +size 10240 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-131.bz2 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-131.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..fa7f7ff1ef7de28afc05c469fef869b93c578e95 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-131.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a89ee3425574c2fc585e4d1c87b9e40c6d68ecf51377a1f21d25f0a25e69cdc5 +size 340 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-256.7z b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-256.7z new file mode 100644 index 0000000000000000000000000000000000000000..4e183cb5cc71a708870d57cf86e7eb82e3953407 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-256.7z @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2684812614b043d3baffb7a2941fe9bef4e585b7060441f24914eaafb98a7945 +size 4069842 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-279-fail.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-279-fail.tar new file mode 100644 index 0000000000000000000000000000000000000000..3a56290935d61ae7e00649740ad454e669f9e0e2 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-279-fail.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be4f54cce9addfb76b8a772d94e40ea029e2131fa76b0d88075d4b5eda8aba24 +size 19000 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-335.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-335.tar new file mode 100644 index 0000000000000000000000000000000000000000..0bef7e96214fcf3244df4d78beb5d913d6446185 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-335.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20f6f1612b7203dd5191d9484365df4f9366f0c632d4ddc4db199f27f6e3c7f3 +size 3072 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-348.7z b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-348.7z new file mode 100644 index 0000000000000000000000000000000000000000..6b6e1123ab60517acbfee0f61b34af37a634cd57 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-348.7z @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb6a43668474b6dd6922f225a409979f9b7bfe33a02c29cfb59900afcf403dee +size 213 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-358.uncompressed b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-358.uncompressed new file mode 100644 index 0000000000000000000000000000000000000000..3dff195a9a2ae2242cb5b80778803bb209149cc8 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-358.uncompressed @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee8e4aaa66bf8ae56d55b3a3ac0ad64ea02b7cfcf8746ca4bd56927ca884e31b +size 219521 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-417.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-417.tar new file mode 100644 index 0000000000000000000000000000000000000000..e59478b939eecb8dd748251df68d0b1117dc3ee6 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-417.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:425ff8fd74131c6ddc2d5a98a0d4ba78baebbca2c3645ee8edbc152e629956b3 +size 10240 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/split_zip_created_by_winrar.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/split_zip_created_by_winrar.zip new file mode 100644 index 0000000000000000000000000000000000000000..2b9cbaf63c7a1d294abfd8a38fabc8d7356cc2e4 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/split_zip_created_by_winrar.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea2d067a99a38f10288b2eed4543337719a41b0e6b8585a87f8728e5e317410a +size 50536 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/zip_to_compare_created_by_winrar.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/zip_to_compare_created_by_winrar.zip new file mode 100644 index 0000000000000000000000000000000000000000..6cb6750d6063ed81dfc847ecc44ff3b22c202063 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_winrar/zip_to_compare_created_by_winrar.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33169cd55b80be1c1b6174d3bf8432b7c239bc5372e2c86e8b7bef95f88e6d81 +size 574820 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z01 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z01 new file mode 100644 index 0000000000000000000000000000000000000000..51be336bbc1c2a86fbe7c7af335ac5842fb6da5d --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z01 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:976bb2c4c8a9093be32824e0b2d112335581aba733d6103e65fcc63bc1560878 +size 262144 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z02 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z02 new file mode 100644 index 0000000000000000000000000000000000000000..78aea40ae7826ab6c2401720258dac4e3b9affad --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.z02 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6cdf0faf9016807160197d017cfd8a59815b5e55c3360f4c98f105ac609dc40 +size 262144 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.zip new file mode 100644 index 0000000000000000000000000000000000000000..270ae6c0dba3c0cb29a90569922c1557c208169a --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb86d35f40656889434d6e69b1055d11dfb44d3d68555a74891f187e6dc3333c +size 57763 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z01 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z01 new file mode 100644 index 0000000000000000000000000000000000000000..5301db470430f13cb300c6bdfeb0ca8a6d1ab946 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z01 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38a2673a82a76deb82bf1897a87b06938fa02119a8382eb80c500e6ca7a67a17 +size 262144 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z02 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z02 new file mode 100644 index 0000000000000000000000000000000000000000..bb193a6074e29e64d85c3bbac37b84369004b622 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.z02 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e6812211e4f5fb3e636e4a700bf8dfd385bac26b36e989a2c97dacf1d25748e +size 262144 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip_zip64.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip_zip64.zip new file mode 100644 index 0000000000000000000000000000000000000000..f37850bff48b0824b3ebfd6c63c97d08c097da30 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip_zip64.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d963653f8c6e22a9e2ec276909aac4d98e00f6951f9b175e7848a135b0920e2f +size 584681 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-492.7z b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-492.7z new file mode 100644 index 0000000000000000000000000000000000000000..a8f25ceec33fa162f67f1bac63774d9c396c1de1 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-492.7z @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f513e29c0c822c3a093c94207ea42cee5a0876a5205dbd0c4adffc05d416e92 +size 39 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-542-endheadercorrupted2.7z b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-542-endheadercorrupted2.7z new file mode 100644 index 0000000000000000000000000000000000000000..72df28708e7838ad99f163c8e8b076f845aca84c --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-542-endheadercorrupted2.7z @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9c92894e9c43fef4eda2591571b978d02df9d1e2c948c5fc95a3ac353971dd4 +size 233 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-548.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-548.zip new file mode 100644 index 0000000000000000000000000000000000000000..222eb181ebc0ddc72217ca369c1b2ba59756553f --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-548.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3bed8be4a2685d261801fc44e90b36fcb1b4abc874982396e9f6720540d38fb4 +size 79 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-569-fail.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-569-fail.tar new file mode 100644 index 0000000000000000000000000000000000000000..34b1b0df437cde54a6d546721fcc436602e776c3 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-569-fail.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ad4603ba7626f88b8f640c4f8543b9b3ace3ec261e4eb5241f02ed397690b3d +size 513 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-592.7z b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-592.7z new file mode 100644 index 0000000000000000000000000000000000000000..1c58d6d9385554215c4c578416aebe655868c2aa --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/COMPRESS-592.7z @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b54836099c4c27e535e8c2b6adf6b092fd66986f8ad586983c590e76cdf46316 +size 1053510 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/OSX_ArchiveWithNestedArchive.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/OSX_ArchiveWithNestedArchive.zip new file mode 100644 index 0000000000000000000000000000000000000000..7f331398d714045b7a95d94f7a935d8d6e89d603 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/OSX_ArchiveWithNestedArchive.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:342ab7e56b45182f962a2fd4b9ad17dff96a1883e9fd42e27c3682b873c73f9c +size 752 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/archive_with_trailer.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/archive_with_trailer.tar new file mode 100644 index 0000000000000000000000000000000000000000..bd39b86bcba0279bda13049ee056852f58e8a2cd --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/archive_with_trailer.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:802283b934ee8e998b136d1195266b85462c5d090ffbc9f36536e7e1a1234812 +size 10254 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-contradicts-actualsize.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-contradicts-actualsize.zip new file mode 100644 index 0000000000000000000000000000000000000000..ecb69d11ddcfa10887a9ca23be83a5d17b53e599 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-contradicts-actualsize.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fe52bd3515c7d18734429e5501aa4f9cd3173f7512370791e9625fcbde1860c +size 1023 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-nosig.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-nosig.zip new file mode 100644 index 0000000000000000000000000000000000000000..cb56261e777da6448de0d67ea8539555b53e876e --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-nosig.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7adcf56c2eb0e95558a0f8ae038158b4502db096b8ed1511bd8246a98e0e7058 +size 1018 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-sizes-differ.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-sizes-differ.zip new file mode 100644 index 0000000000000000000000000000000000000000..60e19e5bd834c4ff9198395b36e0a754aaf3dfb4 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla-stored-dd-sizes-differ.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f39c7f7987ad60de6c6756795ac36201a1ef298b723badf6a2c0b103ee426e29 +size 1022 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.dump.lz4 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.dump.lz4 new file mode 100644 index 0000000000000000000000000000000000000000..53ee9cdf68a6386f73e3c9c3252cbb746a43be1d --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.dump.lz4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83342b842478d51857b590b98a518a70afc186c647ebc4d3d29ea0e2110d9b04 +size 1443 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar new file mode 100644 index 0000000000000000000000000000000000000000..844cb35ef9be1a58122ba4e5cc6491de2348b83c --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e081a961b6a97f68e19cf6e26f3b85e04ffef27dbe9c4ad664d79a7ced06a38 +size 10240 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.br b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.br new file mode 100644 index 0000000000000000000000000000000000000000..382544d89548b489a351c99d60eba5a27457a4f1 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.br @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5412ea63311ed00e13b02580f9298194fbadfca4dd2f9270d2da9a677acd43c +size 401 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.bz2 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..a332d0bfa05647edccfbb7b471f9cb328593e0fc --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:963e492c9542fc377e79d99fbae2f5de0b14b6ad118615c6edcceeb1e49c7747 +size 543 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.deflatez b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.deflatez new file mode 100644 index 0000000000000000000000000000000000000000..c87a3ebb5960434c8b5df31351a207657b4ee583 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.deflatez @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94f7e82a678084ddb8da9e47a188ca698ebf169b8ff539366febcec99dcfde0b +size 468 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.lz4 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.lz4 new file mode 100644 index 0000000000000000000000000000000000000000..66841a09561581dd726243ea73a44d0666a15613 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.tar.lz4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1754153c73567574efc457b05034ec671a94250a38b48fea2d045f0313c7b210 +size 623 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.xml.bz2 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.xml.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..7004f9c5ea6b0b2749d0e748e9eadefb55ef5a75 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bla.xml.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ece0962864bcda997c011042f0677a34d97fc4bc8294dd96fdcb003e38faea89 +size 389 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bzip2-zip.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bzip2-zip.zip new file mode 100644 index 0000000000000000000000000000000000000000..11625a4ab4560924fe9e13f1fb58b4ac1a2e98c7 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/bzip2-zip.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:650a1ad2c88b0ad2f7686dc4502138848cb36016da535692b1a683675c2f5ca5 +size 209 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/directory.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/directory.tar new file mode 100644 index 0000000000000000000000000000000000000000..ebdf5e72572928ce6760bbbdf43c6047fd85de03 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/directory.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:487b432f36ef467a0848331aa2957f6896506e4a5b94fa6a05c23b75a20d265e +size 1536 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/emptyDir.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/emptyDir.tar new file mode 100644 index 0000000000000000000000000000000000000000..9ec7ed568b80013c33e3f307ba7c03664dd17470 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/emptyDir.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:096fc6ad880d4063f863775d96356edcc1752b0c137711f9a50ee207a1bb09c0 +size 2560 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/multiple.bz2 b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/multiple.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..8a2c947c71706a3ef7f9ff1465b0d9495a98564f --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/multiple.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95047070dc140497f68adc8bda5f298fee7611c91e369236491b99025ba8ee16 +size 74 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/pack200/jars/ant.jar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/pack200/jars/ant.jar new file mode 100644 index 0000000000000000000000000000000000000000..dc60a908ad8c216b2d7204b8191501c12b048c98 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/pack200/jars/ant.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12a63db875017c008ea9bb6ca5112d84c14be78d02ad9ea21c4221428a44a824 +size 958858 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/posix01_sparse.tar b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/posix01_sparse.tar new file mode 100644 index 0000000000000000000000000000000000000000..fe2ad26d78e5495038990969090df8fa35f5569a --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/posix01_sparse.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e96dcf7939b20ba863a58cc0f91b72231439da3201ff3c457d06ce4d90f27d9 +size 10240 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/testNumbersNew.numbers b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/testNumbersNew.numbers new file mode 100644 index 0000000000000000000000000000000000000000..10fd20ed857fa29b317fdb5fe07476c181b15e76 --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/testNumbersNew.numbers @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:74a834857c02d06dbc399aff8ba475f7708092e42501cc665d7fa489f385831f +size 179147 diff --git a/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/utf8-winzip-test.zip b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/utf8-winzip-test.zip new file mode 100644 index 0000000000000000000000000000000000000000..21563511e6607315dbf1b5af392ba55392f3c6ad --- /dev/null +++ b/local-test-commons-compress-delta-02/afc-commons-compress/src/test/resources/utf8-winzip-test.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd5aeb74f430739a93b21f107237f74f31de5a59c66729dab68281f47ed1ec61 +size 569 diff --git a/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/ideal_integration.md b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/ideal_integration.md new file mode 100644 index 0000000000000000000000000000000000000000..986e7bc1c034bb591c9b6671a1cfd5f488153c73 --- /dev/null +++ b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/ideal_integration.md @@ -0,0 +1 @@ +This page has moved [here](https://google.github.io/oss-fuzz/advanced-topics/ideal-integration) diff --git a/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/index.md b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/index.md new file mode 100644 index 0000000000000000000000000000000000000000..4e33b8f27b6e1be56068d8f0fe598db3caf5f7d2 --- /dev/null +++ b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/index.md @@ -0,0 +1,88 @@ +--- +layout: default +title: OSS-Fuzz +permalink: / +nav_order: 1 +has_children: true +has_toc: false +--- + +# OSS-Fuzz + +[Fuzz testing] is a well-known technique for uncovering programming errors in +software. Many of these detectable errors, like [buffer overflow], can have +serious security implications. Google has found [thousands] of security +vulnerabilities and stability bugs by deploying [guided in-process fuzzing of +Chrome components], and we now want to share that service with the open source +community. + +[Fuzz testing]: https://en.wikipedia.org/wiki/Fuzz_testing +[buffer overflow]: https://en.wikipedia.org/wiki/Buffer_overflow +[thousands]: https://bugs.chromium.org/p/chromium/issues/list?q=label%3AStability-LibFuzzer%2CStability-AFL%20-status%3ADuplicate%2CWontFix&can=1 +[guided in-process fuzzing of Chrome components]: https://security.googleblog.com/2016/08/guided-in-process-fuzzing-of-chrome.html + +In cooperation with the [Core Infrastructure Initiative] and the [OpenSSF], +OSS-Fuzz aims to make common open source software more secure and stable by +combining modern fuzzing techniques with scalable, distributed execution. +Projects that do not qualify for OSS-Fuzz (e.g. closed source) can run their own +instances of [ClusterFuzz] or [ClusterFuzzLite]. + +[Core Infrastructure Initiative]: https://www.coreinfrastructure.org/ +[OpenSSF]: https://www.openssf.org/ + +We support the [libFuzzer], [AFL++], [Honggfuzz], and [Centipede] fuzzing engines in +combination with [Sanitizers], as well as [ClusterFuzz], a distributed fuzzer +execution environment and reporting tool. + +[libFuzzer]: https://llvm.org/docs/LibFuzzer.html +[AFL++]: https://github.com/AFLplusplus/AFLplusplus +[Honggfuzz]: https://github.com/google/honggfuzz +[Centipede]: https://github.com/google/centipede +[Sanitizers]: https://github.com/google/sanitizers +[ClusterFuzz]: https://github.com/google/clusterfuzz +[ClusterFuzzLite]: https://google.github.io/clusterfuzzlite/ + +Currently, OSS-Fuzz supports C/C++, Rust, Go, Python and Java/JVM code. Other +languages supported by [LLVM] may work too. OSS-Fuzz supports fuzzing x86_64 +and i386 builds. + +[LLVM]: https://llvm.org + + +## Project history +OSS-Fuzz was launched in 2016 in response to the +[Heartbleed] vulnerability, discovered in [OpenSSL], one of the +most popular open source projects for encrypting web traffic. The vulnerability +had the potential to affect almost every internet user, yet was caused by a +relatively simple memory buffer overflow bug that could have been detected by +fuzzing—that is, by running the code on randomized inputs to intentionally cause +unexpected behaviors or crashes. At the time, though, fuzzing +was not widely used and was cumbersome for developers, requiring extensive +manual effort. + +Google created OSS-Fuzz to fill this gap: it's a free service that runs fuzzers +for open source projects and privately alerts developers to the bugs detected. +Since its launch, OSS-Fuzz has become a critical service for the open source +community, growing beyond C/C++ to +detect problems in memory-safe languages such as Go, Rust, and Python. + +[Heartbleed]: https://heartbleed.com/ +[OpenSSL]: https://www.openssl.org/ + +## Learn more about fuzzing + +This documentation describes how to use OSS-Fuzz service for your open source +project. To learn more about fuzzing in general, we recommend reading [libFuzzer +tutorial] and the other docs in [google/fuzzing] repository. These and some +other resources are listed on the [useful links] page. + +[google/fuzzing]: https://github.com/google/fuzzing/tree/master/docs +[libFuzzer tutorial]: https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md +[useful links]: {{ site.baseurl }}/reference/useful-links/#tutorials + +## Trophies +As of August 2023, OSS-Fuzz has helped identify and fix over [10,000] vulnerabilities and [36,000] bugs across [1,000] projects. + +[10,000]: https://bugs.chromium.org/p/oss-fuzz/issues/list?q=Type%3DBug-Security%20label%3Aclusterfuzz%20-status%3ADuplicate%2CWontFix&can=1 +[36,000]: https://bugs.chromium.org/p/oss-fuzz/issues/list?q=Type%3DBug%20label%3Aclusterfuzz%20-status%3ADuplicate%2CWontFix&can=1 +[1,000]: https://github.com/google/oss-fuzz/tree/master/projects diff --git a/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/manifest.py b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/manifest.py new file mode 100644 index 0000000000000000000000000000000000000000..acb3b8d995aeeb4617b36c9862a7bcdb85992081 --- /dev/null +++ b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/manifest.py @@ -0,0 +1,61 @@ +#! /usr/bin/env python3 +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +"""Script for pushing manifest files to docker that point to AMD64 and ARM +images.""" +import logging +import subprocess +import sys + + +def push_manifest(image): + """Pushes a manifest file in place of |image| for ARM and AMD64 versions of + that image.""" + subprocess.run(['docker', 'pull', image], check=True) + amd64_image = f'{image}:manifest-amd64' + subprocess.run(['docker', 'tag', image, amd64_image], check=True) + subprocess.run(['docker', 'push', amd64_image], check=True) + + arm_version = f'{image}-testing-arm' + subprocess.run(['docker', 'pull', arm_version], check=True) + arm64_image = f'{image}:manifest-arm64v8' + subprocess.run(['docker', 'tag', arm_version, arm64_image], check=True) + + subprocess.run([ + 'docker', 'manifest', 'create', image, '--amend', arm64_image, '--amend', + amd64_image + ], + check=True) + subprocess.run(['docker', 'manifest', 'push', image], check=True) + return True + + +def main(): + """Sets up manifests for base-builder and base-runner so they can be used for + ARM builds.""" + logging.info('Doing simple gcloud command to ensure 2FA passes. ' + 'Otherwise docker push fails.') + subprocess.run(['gcloud', 'projects', 'list', '--limit=1'], check=True) + + images = [ + 'ghcr.io/aixcc-finals/base-builder', 'ghcr.io/aixcc-finals/base-runner' + ] + results = [push_manifest(image) for image in images] + return 0 if all(results) else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/pr_helper.py b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/pr_helper.py new file mode 100644 index 0000000000000000000000000000000000000000..4d93b24a5d2f05d85570ec2d10fad5480596c2e2 --- /dev/null +++ b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/pr_helper.py @@ -0,0 +1,300 @@ +#!/usr/bin/env python +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +"""Adds comments for PR to provide more information for approvers.""" +import base64 +import json +import os +import subprocess + +import requests +import yaml + +OWNER = 'google' +REPO = 'oss-fuzz' +GITHUB_URL = 'https://github.com/' +GITHUB_NONREF_URL = f'https://www.github.com/{OWNER}/{REPO}' # Github URL that doesn't send emails on linked issues. +API_URL = 'https://api.github.com' +BASE_URL = f'{API_URL}/repos/{OWNER}/{REPO}' +BRANCH = 'master' +CRITICALITY_SCORE_PATH = '/home/runner/go/bin/criticality_score' +COMMITS_LIMIT = 50 # Only process the most recent 50 commits. + + +def get_criticality_score(repo_url): + """Gets the criticality score of the project.""" + # Criticality score does not support repo url ends with '.git' + if repo_url.endswith('.git'): + repo_url = repo_url[:-4] + report = subprocess.run([ + CRITICALITY_SCORE_PATH, '--format', 'json', + '-gcp-project-id=clusterfuzz-external', '-depsdev-disable', repo_url + ], + capture_output=True, + text=True) + + try: + report_dict = json.loads(report.stdout) + except: + print(f'Criticality score failed with stdout: {report.stdout}') + print(f'Criticality score failed with stderr: {report.stderr}') + return 'N/A' + return report_dict.get('default_score', 'N/A') + + +def is_known_contributor(content, email): + """Checks if the author is in the contact list.""" + return (email == content.get('primary_contact') or + email in content.get('vendor_ccs', []) or + email in content.get('auto_ccs', [])) + + +def save_env(message, is_ready_for_merge, is_internal=False): + """Saves the outputs as environment variables.""" + with open(os.environ['GITHUB_ENV'], 'a') as github_env: + github_env.write(f'MESSAGE={message}\n') + github_env.write(f'IS_READY_FOR_MERGE={is_ready_for_merge}\n') + github_env.write(f'IS_INTERNAL={is_internal}') + + +def main(): + """Verifies if a PR is ready to merge.""" + github = GithubHandler() + + # Bypasses PRs of the internal members. + if github.is_author_internal_member(): + save_env(None, None, True) + return + + message = '' + is_ready_for_merge = True + pr_author = github.get_pr_author() + # Gets all modified projects path. + projects_path = github.get_projects_path() + verified, email = github.get_author_email() + + for project_path in projects_path: + project_url = f'{GITHUB_URL}/{OWNER}/{REPO}/tree/{BRANCH}/{project_path}' + content_dict = github.get_project_yaml(project_path) + + # Gets information for the new integrating project. + if not content_dict: + is_ready_for_merge = False + new_project = github.get_integrated_project_info() + repo_url = new_project.get('main_repo') + if repo_url is None: + message += (f'{pr_author} is integrating a new project, ' + 'but the `main_repo` is missing. ' + 'The criticality score cannot be computed.
') + else: + message += (f'{pr_author} is integrating a new project:
' + f'- Main repo: {repo_url}
- Criticality score: ' + f'{get_criticality_score(repo_url)}
') + continue + + # Checks if the author is in the contact list. + if email: + if is_known_contributor(content_dict, email): + # Checks if the email is verified. + verified_marker = ' (verified)' if verified else '' + message += ( + f'{pr_author}{verified_marker} is either the primary contact or ' + f'is in the CCs list of [{project_path}]({project_url}).
') + if verified: + continue + + # Checks the previous commits. + commit_sha = github.has_author_modified_project(project_path) + if commit_sha is None: + history_message = '' + contributors = github.get_past_contributors(project_path) + if contributors: + history_message = 'The past contributors are: ' + history_message += ', '.join(contributors) + message += ( + f'{pr_author} is a new contributor to ' + f'[{project_path}]({project_url}). The PR must be approved by known ' + f'contributors before it can be merged. {history_message}
') + is_ready_for_merge = False + continue + + # If the previous commit is not associated with a pull request. + pr_message = (f'{pr_author} has previously contributed to ' + f'[{project_path}]({project_url}). The previous commit was ' + f'{GITHUB_NONREF_URL}/commit/{commit_sha}
') + + previous_pr_number = github.get_pull_request_number(commit_sha) + if previous_pr_number is not None: + pr_message = (f'{pr_author} has previously contributed to ' + f'[{project_path}]({project_url}). ' + f'The previous PR was [#{previous_pr_number}]' + f'({GITHUB_NONREF_URL}/pull/{previous_pr_number})
') + message += pr_message + + save_env(message, is_ready_for_merge, False) + + +class GithubHandler: + """Github requests handler.""" + + def __init__(self): + self._pr_author = os.environ['PRAUTHOR'] + self._token = os.environ['GITHUBTOKEN'] + self._pr_number = os.environ['PRNUMBER'] + self._headers = { + 'Authorization': f'Bearer {self._token}', + 'X-GitHub-Api-Version': '2022-11-28' + } + self._maintainers = set() + os.environ['GITHUB_AUTH_TOKEN'] = self._token + + def get_pr_author(self): + """Gets the pr author user name.""" + return self._pr_author + + def get_projects_path(self): + """Gets the current project path.""" + response = requests.get(f'{BASE_URL}/pulls/{self._pr_number}/files', + headers=self._headers) + if not response.ok: + return [] + + projects_path = set() + for file in response.json(): + file_path = file['filename'] + dir_path = file_path.split(os.sep) + if len(dir_path) > 1 and dir_path[0] == 'projects': + projects_path.add(os.sep.join(dir_path[0:2])) + return list(projects_path) + + def get_author_email(self): + """Retrieves the author's email address for a pull request, + including non-public emails.""" + user_response = requests.get(f'{API_URL}/users/{self._pr_author}') + if user_response.ok: + email = user_response.json()['email'] + if email: + return True, email + + commits_response = requests.get( + f'{BASE_URL}/pulls/{self._pr_number}/commits', headers=self._headers) + if not commits_response.ok: + return False, None + email = commits_response.json()[0]['commit']['author']['email'] + verified = commits_response.json()[0]['commit']['verification']['verified'] + return verified, email + + def get_project_yaml(self, project_path): + """Gets the project yaml file.""" + contents_url = f'{BASE_URL}/contents/{project_path}/project.yaml' + return self.get_yaml_file_content(contents_url) + + def get_yaml_file_content(self, contents_url): + """Gets yaml file content.""" + response = requests.get(contents_url, headers=self._headers) + if not response.ok: + return {} + content = base64.b64decode(response.json()['content']).decode('UTF-8') + return yaml.safe_load(content) + + def get_integrated_project_info(self): + """Gets the new integrated project.""" + response = requests.get(f'{BASE_URL}/pulls/{self._pr_number}/files', + headers=self._headers) + + for file in response.json(): + file_path = file['filename'] + if 'project.yaml' in file_path: + return self.get_yaml_file_content(file['contents_url']) + + return {} + + def get_pull_request_number(self, commit): + """Gets the pull request number.""" + pr_response = requests.get(f'{BASE_URL}/commits/{commit}/pulls', + headers=self._headers) + if not pr_response.ok: + return None + return pr_response.json()[0]['number'] + + def get_past_contributors(self, project_path): + """Returns a list of past contributors of a certain project.""" + commits_response = requests.get(f'{BASE_URL}/commits?path={project_path}', + headers=self._headers) + + if not commits_response.ok: + return [] + commits = commits_response.json() + contributors: dict[str, bool] = {} + for i, commit in enumerate(commits): + if i >= COMMITS_LIMIT: + break + + if not commit['author'] or not commit['commit']: + continue + + login = commit['author']['login'] + verified = commit['commit']['verification']['verified'] + if login in self._maintainers: + continue + if login not in contributors: + contributors[login] = verified + if verified: + # Override previous verification bit. + contributors[login] = True + + all_contributors = [] + for login, verified in contributors.items(): + login_verify = login if verified else f'{login} (unverified)' + all_contributors.append(login_verify) + + return all_contributors + + def get_maintainers(self): + """Get a list of internal members.""" + if self._maintainers: + return self._maintainers + + response = requests.get(f'{BASE_URL}/contents/infra/MAINTAINERS.csv', + headers=self._headers) + if not response.ok: + return self._maintainers + + maintainers_file = base64.b64decode( + response.json()['content']).decode('UTF-8') + for line in maintainers_file.split(os.linesep): + self._maintainers.add(line.split(',')[2]) + return self._maintainers + + def is_author_internal_member(self): + """Returns if the author is an internal member.""" + return self._pr_author in self.get_maintainers() + + def has_author_modified_project(self, project_path): + """Checks if the author has modified this project before.""" + commits_response = requests.get( + f'{BASE_URL}/commits?path={project_path}&author={self._pr_author}', + headers=self._headers) + + if not commits_response.ok or not commits_response.json(): + return None + + commit = commits_response.json()[0] + return commit['sha'] + + +if __name__ == '__main__': + main() diff --git a/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/presubmit.py b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/presubmit.py new file mode 100644 index 0000000000000000000000000000000000000000..41633fa256a73518f09fcf8ad8f9e40c7ad845c7 --- /dev/null +++ b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/presubmit.py @@ -0,0 +1,549 @@ +#!/usr/bin/env python3 +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +"""Checks code for common issues before submitting.""" + +import argparse +import os +import re +import subprocess +import sys +import unittest +import yaml + +import constants + +_SRC_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +VALID_PROJECT_REGEX_STR = '^[a-z0-9_-]+$' +VALID_PROJECT_REGEX = re.compile(VALID_PROJECT_REGEX_STR) + + +def _is_project_file(actual_path, expected_filename): + """Returns True if actual_path's name is |expected_filename| and is a file + that exists and is in in projects/.""" + if os.path.basename(actual_path) != expected_filename: + return False + + if os.path.basename(os.path.dirname( + os.path.dirname(actual_path))) != 'projects': + return False + + return os.path.exists(actual_path) + + +# TODO: Check for -fsanitize=fuzzer in files as well. + + +def _check_one_lib_fuzzing_engine(build_sh_file): + """Returns False if |build_sh_file| contains -lFuzzingEngine. + This is deprecated behavior. $LIB_FUZZING_ENGINE should be used instead + so that -fsanitize=fuzzer is used.""" + if not _is_project_file(build_sh_file, 'build.sh'): + return True + + with open(build_sh_file) as build_sh: + build_sh_lines = build_sh.readlines() + for line_num, line in enumerate(build_sh_lines): + uncommented_code = line.split('#')[0] + if '-lFuzzingEngine' in uncommented_code: + print('Error: build.sh contains deprecated "-lFuzzingEngine" on line: ' + f'{line_num}. Please use "$LIB_FUZZING_ENGINE" instead.') + return False + return True + + +def check_lib_fuzzing_engine(paths): + """Calls _check_one_lib_fuzzing_engine on each path in |paths|. Returns True + if the result of every call is True.""" + return all(_check_one_lib_fuzzing_engine(path) for path in paths) + + +class ProjectYamlChecker: + """Checks for a project.yaml file.""" + + # Sections in a project.yaml and the constant values that they are allowed + # to have. + SECTIONS_AND_CONSTANTS = { + 'sanitizers': constants.SANITIZERS, + 'architectures': constants.ARCHITECTURES, + 'fuzzing_engines': constants.ENGINES, + } + + # Note: this list must be updated when we allow new sections. + VALID_SECTION_NAMES = [ + 'architectures', + 'auto_ccs', + 'blackbox', + 'builds_per_day', + 'coverage_extra_args', + 'disabled', + 'fuzzing_engines', + 'help_url', + 'homepage', + 'language', + 'labels', # For internal use only, hard to lint as it uses fuzzer names. + 'main_repo', + 'primary_contact', + 'run_tests', + 'sanitizers', + 'selective_unpack', + 'vendor_ccs', + 'view_restrictions', + 'file_github_issue', + ] + + REQUIRED_SECTIONS = ['main_repo'] + + def __init__(self, filename): + self.filename = filename + with open(filename) as file_handle: + self.data = yaml.safe_load(file_handle) + + self.success = True + + def do_checks(self): + """Does all project.yaml checks. Returns True if they pass.""" + if self.is_disabled(): + return True + + checks = [ + self.check_project_yaml_constants, + self.check_required_sections, + self.check_valid_section_names, + self.check_valid_emails, + self.check_valid_language, + self.check_valid_project_name, + ] + for check_function in checks: + check_function() + return self.success + + def is_disabled(self): + """Returns True if this project is disabled.""" + return self.data.get('disabled', False) + + def error(self, message): + """Prints an error message and sets self.success to False.""" + self.success = False + print(f'Error in {self.filename}: {message}') + + def check_valid_project_name(self): + """Checks that the project has a valid name.""" + banned_names = ['google', 'g00gle'] + project_name = os.path.basename(os.path.dirname(self.filename)) + for banned_name in banned_names: + if banned_name in project_name: + self.error('Projects can\'t have \'google\' in the name.') + if not VALID_PROJECT_REGEX.match(project_name): + self.error(f'Projects must conform to regex {VALID_PROJECT_REGEX_STR}') + + def check_project_yaml_constants(self): + """Returns True if certain sections only have certain constant values.""" + for section, allowed_constants in self.SECTIONS_AND_CONSTANTS.items(): + if section not in self.data: + continue + actual_constants = self.data[section] + allowed_constants_str = ', '.join(allowed_constants) + for constant in actual_constants: + if isinstance(constant, str): + if constant not in allowed_constants: + self.error(f'{constant} (in {section} section) is not a valid ' + f'constant ({allowed_constants_str}).') + elif isinstance(constant, dict): + # The only alternative value allowed is the experimental flag, i.e. + # `constant == {'memory': {'experimental': True}}`. Do not check the + # experimental flag, but assert that the sanitizer is a valid one. + if (len(constant.keys()) > 1 or + list(constant.keys())[0] not in allowed_constants): + self.error(f'Not allowed value in the project.yaml: {constant}') + else: + self.error(f'Not allowed value in the project.yaml: {constant}') + + def check_valid_section_names(self): + """Returns True if all section names are valid.""" + for name in self.data: + if name not in self.VALID_SECTION_NAMES: + self.error( + f'{name} is not a valid section name ({self.VALID_SECTION_NAMES})') + + def check_required_sections(self): + """Returns True if all required sections are in |self.data|.""" + for section in self.REQUIRED_SECTIONS: + if section not in self.data: + self.error(f'{section} section is missing.') + + def check_valid_emails(self): + """Returns True if emails are valid looking..""" + # Get email addresses. + email_addresses = [] + primary_contact = self.data.get('primary_contact') + if primary_contact: + email_addresses.append(primary_contact) + auto_ccs = self.data.get('auto_ccs') + if auto_ccs: + email_addresses.extend(auto_ccs) + + # Check that email addresses seem normal. + for email_address in email_addresses: + if '@' not in email_address or '.' not in email_address: + self.error(f'{email_address} is an invalid email address.') + + def check_valid_language(self): + """Returns True if the language is specified and valid.""" + language = self.data.get('language') + if not language: + self.error('Missing "language" attribute in project.yaml.') + elif language not in constants.LANGUAGES: + self.error( + f'"language: {language}" is not supported ({constants.LANGUAGES}).') + + +def _check_one_project_yaml(project_yaml_filename): + """Does checks on the project.yaml file. Returns True on success.""" + if _is_project_file(project_yaml_filename, 'project.yml'): + print(project_yaml_filename, 'must be named project.yaml.') + return False + + if not _is_project_file(project_yaml_filename, 'project.yaml'): + return True + + checker = ProjectYamlChecker(project_yaml_filename) + return checker.do_checks() + + +def check_project_yaml(paths): + """Calls _check_one_project_yaml on each path in |paths|. Returns True if the + result of every call is True.""" + return all([_check_one_project_yaml(path) for path in paths]) + + +def _check_one_seed_corpus(path): + """Returns False and prints error if |path| is a seed corpus.""" + if os.path.basename(os.path.dirname(os.path.dirname(path))) != 'projects': + return True + + if os.path.splitext(path)[1] == '.zip': + print('Don\'t commit seed corpora into the ClusterFuzz repo,' + 'they bloat it forever.') + return False + + return True + + +def check_seed_corpus(paths): + """Calls _check_one_seed_corpus on each path in |paths|. Returns True if the + result of every call is True.""" + return all([_check_one_seed_corpus(path) for path in paths]) + + +def _check_one_apt_update(path): + """Checks that a Dockerfile uses apt-update before apt-install""" + if os.path.basename(os.path.dirname(os.path.dirname(path))) != 'projects': + return True + + if os.path.basename(path) != 'Dockerfile': + return True + + with open(path, 'r') as file: + dockerfile = file.read() + if 'RUN apt install' in dockerfile or 'RUN apt-get install' in dockerfile: + print('Please add an "apt-get update" before "apt-get install". ' + 'Otherwise, a cached and outdated RUN layer may lead to install ' + 'failures in file %s.' % str(path)) + return False + + return True + + +def check_apt_update(paths): + """Checks that all Dockerfile use apt-update before apt-install""" + return all([_check_one_apt_update(path) for path in paths]) + + +def do_checks(changed_files): + """Runs all presubmit checks. Returns False if any fails.""" + checks = [ + check_license, + yapf, + check_project_yaml, + check_lib_fuzzing_engine, + check_seed_corpus, + check_apt_update, + ] + # Use a list comprehension here and in other cases where we use all() so that + # we don't quit early on failure. This is more user-friendly since the more + # errors we spit out at once, the less frequently the less check-fix-check + # cycles they need to do. + return all([check(changed_files) for check in checks]) + + +_CHECK_LICENSE_FILENAMES = ['Dockerfile'] +_CHECK_LICENSE_EXTENSIONS = [ + '.bash', + '.c', + '.cc', + '.cpp', + '.css', + '.Dockerfile', + '.go', + '.h', + '.htm', + '.html', + '.java', + '.js', + '.proto', + '.py', + '.rs', + '.sh', + '.ts', +] +THIRD_PARTY_DIR_NAME = 'third_party' + +_LICENSE_STRING = 'http://www.apache.org/licenses/LICENSE-2.0' + + +def check_license(paths): + """Validates license header.""" + if not paths: + return True + + success = True + for path in paths: + path_parts = str(path).split(os.sep) + if any(path_part == THIRD_PARTY_DIR_NAME for path_part in path_parts): + continue + filename = os.path.basename(path) + extension = os.path.splitext(path)[1] + if (filename not in _CHECK_LICENSE_FILENAMES and + extension not in _CHECK_LICENSE_EXTENSIONS): + continue + + with open(path) as file_handle: + if _LICENSE_STRING not in file_handle.read(): + print('Missing license header in file %s.' % str(path)) + success = False + + return success + + +def bool_to_returncode(success): + """Returns 0 if |success|. Otherwise returns 1.""" + if success: + print('Success.') + return 0 + + print('Failed.') + return 1 + + +def is_nonfuzzer_python(path): + """Returns True if |path| ends in .py.""" + return os.path.splitext(path)[1] == '.py' and '/projects/' not in path + + +def lint(_=None): + """Runs python's linter on infra. Returns False if it fails linting.""" + + # Use --score no to make linting quieter. + command = ['python3', '-m', 'pylint', '--score', 'no', '-j', '0', 'infra'] + returncode = subprocess.run(command, check=False).returncode + return returncode == 0 + + +def yapf(paths, validate=True): + """Does yapf on |path| if it is Python file. Only validates format if + |validate|. Otherwise, formats the file. Returns False if validation or + formatting fails.""" + paths = [path for path in paths if is_nonfuzzer_python(path)] + if not paths: + return True + + validate_argument = '-d' if validate else '-i' + command = ['yapf', validate_argument, '-p'] + command.extend(paths) + + returncode = subprocess.run(command, check=False).returncode + return returncode == 0 + + +def get_changed_files(): + """Returns a list of absolute paths of files changed in this git branch.""" + branch_commit_hash = subprocess.check_output( + ['git', 'merge-base', 'HEAD', 'origin/HEAD']).strip().decode() + + diff_commands = [ + # Return list of modified files in the commits on this branch. + ['git', 'diff', '--name-only', branch_commit_hash + '..'], + # Return list of modified files from uncommitted changes. + ['git', 'diff', '--name-only'] + ] + + changed_files = set() + for command in diff_commands: + file_paths = subprocess.check_output(command).decode().splitlines() + for file_path in file_paths: + if not os.path.isfile(file_path): + continue + changed_files.add(file_path) + print(f'Changed files: {" ".join(changed_files)}') + return [os.path.abspath(f) for f in changed_files] + + +def run_build_tests(): + """Runs build tests because they can't be run in parallel.""" + suite_list = [ + unittest.TestLoader().discover(os.path.join(_SRC_ROOT, 'infra', 'build'), + pattern='*_test.py'), + ] + suite = unittest.TestSuite(suite_list) + print('Running build tests.') + result = unittest.TextTestRunner().run(suite) + return not result.failures and not result.errors + + +def run_nonbuild_tests(parallel): + """Runs all tests but build tests. Does them in parallel if |parallel|. The + reason why we exclude build tests is because they use an emulator that + prevents them from being used in parallel.""" + # We look for all project directories because otherwise pytest won't run tests + # that are not in valid modules (e.g. "base-images"). + relevant_dirs = set() + all_files = get_all_files() + for file_path in all_files: + directory = os.path.dirname(file_path) + relevant_dirs.add(directory) + + # Use ignore-glob because ignore doesn't seem to work properly with the way we + # pass directories to pytest. + command = [ + 'pytest', + '--ignore-glob=infra/build/*', + '--ignore-glob=projects/*', + ] + if parallel: + command.extend(['-n', 'auto']) + command += list(relevant_dirs) + print('Running non-build tests.') + + # TODO(metzman): Get rid of this once config_utils stops using it. + env = os.environ.copy() + env['CIFUZZ_TEST'] = '1' + + return subprocess.run(command, check=False, env=env).returncode == 0 + + +def run_tests(_=None, parallel=False, build_tests=True, nonbuild_tests=True): + """Runs all unit tests.""" + build_success = True + nonbuild_success = True + if nonbuild_tests: + nonbuild_success = run_nonbuild_tests(parallel) + else: + print('Skipping nonbuild tests as specified.') + + if build_tests: + build_success = run_build_tests() + else: + print('Skipping build tests as specified.') + + return nonbuild_success and build_success + + +def run_systemsan_tests(_=None): + """Runs SystemSan unit tests.""" + command = ['make', 'test'] + return subprocess.run(command, + cwd='infra/experimental/SystemSan', + check=False).returncode == 0 + + +def get_all_files(): + """Returns a list of absolute paths of files in this repo.""" + get_all_files_command = ['git', 'ls-files'] + output = subprocess.check_output(get_all_files_command).decode().splitlines() + return [os.path.abspath(path) for path in output if os.path.isfile(path)] + + +def main(): + """Check changes on a branch for common issues before submitting.""" + # Get program arguments. + parser = argparse.ArgumentParser(description='Presubmit script for oss-fuzz.') + parser.add_argument( + 'command', + choices=['format', 'lint', 'license', 'infra-tests', 'systemsan-tests'], + nargs='?') + parser.add_argument('-a', + '--all-files', + action='store_true', + help='Run presubmit check(s) on all files', + default=False) + parser.add_argument('-p', + '--parallel', + action='store_true', + help='Run tests in parallel.', + default=False) + parser.add_argument('-s', + '--skip-build-tests', + action='store_true', + help='Skip build tests which are slow and must run ' + 'sequentially.', + default=False) + parser.add_argument('-n', + '--skip-nonbuild-tests', + action='store_true', + help='Only do build tests.', + default=False) + args = parser.parse_args() + + if args.all_files: + relevant_files = get_all_files() + else: + relevant_files = get_changed_files() + + os.chdir(_SRC_ROOT) + + # Do one specific check if the user asked for it. + if args.command == 'format': + success = yapf(relevant_files, False) + return bool_to_returncode(success) + + if args.command == 'lint': + success = lint() + return bool_to_returncode(success) + + if args.command == 'license': + success = check_license(relevant_files) + return bool_to_returncode(success) + + if args.command == 'infra-tests': + success = run_tests(relevant_files, + parallel=args.parallel, + build_tests=(not args.skip_build_tests), + nonbuild_tests=(not args.skip_nonbuild_tests)) + return bool_to_returncode(success) + + if args.command == 'systemsan-tests': + success = run_systemsan_tests(relevant_files) + return bool_to_returncode(success) + + # Do all the checks (but no tests). + success = do_checks(relevant_files) + + return bool_to_returncode(success) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/retry.py b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/retry.py new file mode 100644 index 0000000000000000000000000000000000000000..1f6d54b8d00d081b672a7cbb9f998b5b92c624ce --- /dev/null +++ b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/retry.py @@ -0,0 +1,106 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Retry decorator. Copied from ClusterFuzz source.""" + +import functools +import inspect +import logging +import sys +import time + +# pylint: disable=too-many-arguments,broad-except + + +def sleep(seconds): + """Invoke time.sleep. This is to avoid the flakiness of time.sleep. See: + crbug.com/770375""" + time.sleep(seconds) + + +def get_delay(num_try, delay, backoff): + """Compute backoff delay.""" + return delay * (backoff**(num_try - 1)) + + +def wrap(retries, + delay, + backoff=2, + exception_type=Exception, + retry_on_false=False): + """Retry decorator for a function.""" + + assert delay > 0 + assert backoff >= 1 + assert retries >= 0 + + def decorator(func): + """Decorator for the given function.""" + tries = retries + 1 + is_generator = inspect.isgeneratorfunction(func) + function_with_type = func.__qualname__ + if is_generator: + function_with_type += ' (generator)' + + def handle_retry(num_try, exception=None): + """Handle retry.""" + if (exception is None or + isinstance(exception, exception_type)) and num_try < tries: + logging.info('Retrying on %s failed with %s. Retrying again.', + function_with_type, + sys.exc_info()[1]) + sleep(get_delay(num_try, delay, backoff)) + return True + + logging.error('Retrying on %s failed with %s. Raise.', function_with_type, + sys.exc_info()[1]) + return False + + @functools.wraps(func) + def _wrapper(*args, **kwargs): + """Regular function wrapper.""" + for num_try in range(1, tries + 1): + try: + result = func(*args, **kwargs) + if retry_on_false and not result: + if not handle_retry(num_try): + return result + + continue + return result + except Exception as error: + if not handle_retry(num_try, exception=error): + raise + + @functools.wraps(func) + def _generator_wrapper(*args, **kwargs): + """Generator function wrapper.""" + # This argument is not applicable for generator functions. + assert not retry_on_false + already_yielded_element_count = 0 + for num_try in range(1, tries + 1): + try: + for index, result in enumerate(func(*args, **kwargs)): + if index >= already_yielded_element_count: + yield result + already_yielded_element_count += 1 + break + except Exception as error: + if not handle_retry(num_try, exception=error): + raise + + if is_generator: + return _generator_wrapper + return _wrapper + + return decorator diff --git a/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/utils_test.py b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/utils_test.py new file mode 100644 index 0000000000000000000000000000000000000000..9b7fbc90323af958c2d9fdcbe5d7889b84f0db2b --- /dev/null +++ b/local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/utils_test.py @@ -0,0 +1,151 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Tests the functionality of the utils module's functions""" + +import os +import tempfile +import unittest +from unittest import mock + +import utils +import helper + +EXAMPLE_PROJECT = 'example' + +TEST_OUT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), + 'cifuzz', 'test_data', 'build-out') + + +class IsFuzzTargetLocalTest(unittest.TestCase): + """Tests the is_fuzz_target_local function.""" + + def test_invalid_filepath(self): + """Tests the function with an invalid file path.""" + is_local = utils.is_fuzz_target_local('not/a/real/file') + self.assertFalse(is_local) + is_local = utils.is_fuzz_target_local('') + self.assertFalse(is_local) + is_local = utils.is_fuzz_target_local(' ') + self.assertFalse(is_local) + + def test_valid_filepath(self): + """Checks is_fuzz_target_local function with a valid filepath.""" + + is_local = utils.is_fuzz_target_local( + os.path.join(TEST_OUT_DIR, 'example_crash_fuzzer')) + self.assertTrue(is_local) + is_local = utils.is_fuzz_target_local(TEST_OUT_DIR) + self.assertFalse(is_local) + + +class GetFuzzTargetsTest(unittest.TestCase): + """Tests the get_fuzz_targets function.""" + + def test_valid_filepath(self): + """Tests that fuzz targets can be retrieved once the fuzzers are built.""" + fuzz_targets = utils.get_fuzz_targets(TEST_OUT_DIR) + crash_fuzzer_path = os.path.join(TEST_OUT_DIR, 'example_crash_fuzzer') + nocrash_fuzzer_path = os.path.join(TEST_OUT_DIR, 'example_nocrash_fuzzer') + self.assertCountEqual(fuzz_targets, + [crash_fuzzer_path, nocrash_fuzzer_path]) + + # Testing on a arbitrary directory with no fuzz targets in it. + fuzz_targets = utils.get_fuzz_targets( + os.path.join(helper.OSS_FUZZ_DIR, 'infra', 'travis')) + self.assertFalse(fuzz_targets) + + def test_invalid_filepath(self): + """Tests what get_fuzz_targets return when invalid filepath is used.""" + fuzz_targets = utils.get_fuzz_targets('not/a/valid/file/path') + self.assertFalse(fuzz_targets) + + +class ExecuteTest(unittest.TestCase): + """Tests the execute function.""" + + def test_valid_command(self): + """Tests that execute can produce valid output.""" + with tempfile.TemporaryDirectory() as tmp_dir: + out, err, err_code = utils.execute(['ls', '.'], + location=tmp_dir, + check_result=False) + self.assertEqual(err_code, 0) + self.assertEqual(err, '') + self.assertEqual(out, '') + out, err, err_code = utils.execute(['mkdir', 'tmp'], + location=tmp_dir, + check_result=False) + self.assertEqual(err_code, 0) + self.assertEqual(err, '') + self.assertEqual(out, '') + out, err, err_code = utils.execute(['ls', '.'], + location=tmp_dir, + check_result=False) + self.assertEqual(err_code, 0) + self.assertEqual(err, '') + self.assertEqual(out, 'tmp\n') + + def test_error_command(self): + """Tests that execute can correctly surface errors.""" + with tempfile.TemporaryDirectory() as tmp_dir: + out, err, err_code = utils.execute(['ls', 'notarealdir'], + location=tmp_dir, + check_result=False) + self.assertEqual(err_code, 2) + self.assertIsNotNone(err) + self.assertEqual(out, '') + with self.assertRaises(RuntimeError): + out, err, err_code = utils.execute(['ls', 'notarealdir'], + location=tmp_dir, + check_result=True) + + +class BinaryPrintTest(unittest.TestCase): + """Tests for utils.binary_print.""" + + @unittest.skip('Causes spurious failures because of side-effects.') + def test_string(self): # pylint: disable=no-self-use + """Tests that utils.binary_print can print a regular string.""" + # Should execute without raising any exceptions. + with mock.patch('sys.stdout.buffer.write') as mock_write: + utils.binary_print('hello') + mock_write.assert_called_with('hello\n') + + @unittest.skip('Causes spurious failures because of side-effects.') + def test_binary_string(self): # pylint: disable=no-self-use + """Tests that utils.binary_print can print a bianry string.""" + # Should execute without raising any exceptions. + with mock.patch('sys.stdout.buffer.write') as mock_write: + utils.binary_print(b'hello') + mock_write.assert_called_with(b'hello\n') + + +class CommandToStringTest(unittest.TestCase): + """Tests for command_to_string.""" + + def test_string(self): + """Tests that command_to_string returns the argument passed to it when it is + passed a string.""" + command = 'command' + self.assertEqual(utils.command_to_string(command), command) + + def test_list(self): + """Tests that command_to_string returns the correct stringwhen it is passed + a list.""" + command = ['command', 'arg1', 'arg2'] + self.assertEqual(utils.command_to_string(command), 'command arg1 arg2') + + +if __name__ == '__main__': + unittest.main()