Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/vsizip/: add read support for Deflate64 (fixes #7013) #7014

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added autotest/gcore/data/deflate64.zip
Binary file not shown.
33 changes: 33 additions & 0 deletions autotest/gcore/vsizip.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,36 @@ def test_vsizip_byte_zip64_local_header_zeroed():
"/vsizip/data/byte_zip64_local_header_zeroed.zip/byte.tif"
).size
assert size == 736


###############################################################################
def test_vsizip_deflate64():

filename = "/vsizip/data/deflate64.zip/100k_lines.txt"
size = gdal.VSIStatL(filename).size
assert size == 2188890

f = gdal.VSIFOpenL(filename, "rb")
assert f
try:
data = gdal.VSIFReadL(1, size, f)
assert len(data) == size
assert len(gdal.VSIFReadL(1, 1, f)) == 0
assert gdal.VSIFSeekL(f, 0, 0) == 0
data2 = gdal.VSIFReadL(1, size, f)
len_data2 = len(data2)
assert len_data2 == size
assert data2 == data
for (pos, nread) in [
(10000, 1000),
(1, 1),
(size - 1, 1),
(size // 2, size // 2 + 10),
]:
assert gdal.VSIFSeekL(f, pos, 0) == 0
data2 = gdal.VSIFReadL(1, nread, f)
len_data2 = len(data2)
assert len_data2 == min(nread, size - pos), (pos, nread)
assert data2 == data[pos : pos + len_data2], (pos, nread)
finally:
gdal.VSIFCloseL(f)
18 changes: 18 additions & 0 deletions frmts/zlib/contrib/infback9/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_library(
infback9 OBJECT
infback9.c
inftree9.c
minified_zutil.c)
set_property(TARGET infback9 PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:infback9>)
target_compile_options(infback9 PRIVATE ${GDAL_C_WARNING_FLAGS})
if (MSVC)
target_compile_options(infback9 PRIVATE ${GDAL_SOFTWARNFLAGS} /wd4131)
endif ()

include(GdalDriverHelper)
if (GDAL_USE_ZLIB_INTERNAL)
gdal_add_vendored_lib(infback9 libz)
else()
gdal_target_link_libraries(infback9 PRIVATE ZLIB::ZLIB)
endif ()
10 changes: 10 additions & 0 deletions frmts/zlib/contrib/infback9/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Modified copy of zlib from https://github.com/brianhelba/zipfile-deflate64
(at https://github.com/cielavenir/zlib_infback9_resumable/tree/beaec8dc39f5caa86e808611b10f2ea0ab8720c2)

zipfile-deflate64 modified copy has logic to save & restore
state at beginning and end of inflateBack9(), to allow incremental decoding.

GDAL's changes are regarding the "left" and "put" variables

GDAL also adds a inflateBack9Copy() to allow snapshoting of decompression
state.
Loading