diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 795eafe3..4a64ff77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,9 @@ jobs: cmake --build build tree -sha build - name: Test - run: ASAN_OPTIONS=detect_leaks=0 LSAN_OPTIONS=verbosity=1:log_threads=1 cmake --build build --target test + run: | + cd build + ASAN_OPTIONS=detect_leaks=0 LSAN_OPTIONS=verbosity=1:log_threads=1 CTEST_OUTPUT_ON_FAILURE=1 ctest -VV --output-on-failure macos: runs-on: macos-latest @@ -33,7 +35,9 @@ jobs: cmake --build build tree -sha build - name: Test - run: cmake --build build --target test + run: | + cd build + CTEST_OUTPUT_ON_FAILURE=1 ctest -VV --output-on-failure # freebsd: # runs-on: macos-latest @@ -63,7 +67,7 @@ jobs: - name: Test run: | cd build - ctest -VV -C "Debug" + ctest -VV -C "Debug" --output-on-failure windows-mingw: runs-on: "windows-latest" @@ -76,4 +80,6 @@ jobs: cmake --build build tree /a /f build - name: Test - run: cmake --build build --target test + run: | + cd build + ctest -VV -C "Debug" --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f10e0c1..685f6f93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.17) project(zip LANGUAGES C diff --git a/src/zip.c b/src/zip.c index 98f4e40f..2c24e9e2 100644 --- a/src/zip.c +++ b/src/zip.c @@ -589,15 +589,16 @@ static int zip_entry_finalize(struct zip_t *zip, const ssize_t n) { ssize_t i = 0; - mz_uint64 *local_header_ofs_array = (mz_uint64 *)calloc(n, sizeof(mz_uint64)); - if (!local_header_ofs_array) { - return ZIP_EOOMEM; - } if(n == 0) { return 0; } + mz_uint64 *local_header_ofs_array = (mz_uint64 *)calloc(n, sizeof(mz_uint64)); + if (!local_header_ofs_array) { + return ZIP_EOOMEM; + } + for (i = 0; i < n; ++i) { local_header_ofs_array[i] = entry_mark[i].m_local_header_ofs; ssize_t index = zip_sort(local_header_ofs_array, i); @@ -1843,7 +1844,15 @@ struct zip_t *zip_stream_openwitherror(const char *stream, size_t size, // for modes 'd' and 'w', would be better to use mz_zip_reader_init_writer, but there's no clean // way to load the existing stream with that. if ((stream != NULL) && (size > 0) && (mode == 'r' || mode == 'd' || mode == 'w')) { - if (!mz_zip_reader_init_mem(&(zip->archive), stream, size, 0)) { + uint8_t *stream_copy = (uint8_t *)malloc(size); + + if(!stream_copy) { + *errnum = ZIP_EOOMEM; + goto cleanup; + } + memcpy(stream_copy, stream, size); + + if (!mz_zip_reader_init_mem(&(zip->archive), stream_copy, size, 0)) { *errnum = ZIP_ERINIT; goto cleanup; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3a8d7cab..5dae8aa6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.17) find_package(Sanitizers) diff --git a/test/test_entry.c b/test/test_entry.c index 7fae49d8..857edffc 100644 --- a/test/test_entry.c +++ b/test/test_entry.c @@ -410,7 +410,7 @@ MU_TEST(test_entries_delete_stream) { zdata = (uint8_t *)malloc(zsize); mu_check(zdata != NULL); - rc = fread(zdata, zsize, 1, fh); + rc = fread(zdata, sizeof(uint8_t), zsize, fh); mu_check(rc >= 1); fclose(fh); @@ -424,10 +424,13 @@ MU_TEST(test_entries_delete_stream) { zip_stream_copy(zip, (void **)&modified_zdata, &zsize); mu_check(modified_zdata != NULL); - zip_stream_close(zip); free(zdata); zdata = NULL; + // Note that zip_stream_close will free the zdata passed in zip_stream_open + zip_stream_close(zip); + zdata = NULL; + zip = zip_stream_open(modified_zdata, zsize, 0, 'r'); mu_check(zip != NULL);