Skip to content
Open
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
12 changes: 6 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import warnings
import os
from datetime import datetime as dt

Expand Down Expand Up @@ -67,7 +68,6 @@

# Suppress known deprecation warnings from dependencies
# astroid 4.x deprecation - will be fixed when sphinx-autoapi updates for astroid 5.x
import warnings
warnings.filterwarnings(
'ignore',
message="importing .* from 'astroid' is deprecated",
Expand Down Expand Up @@ -180,9 +180,9 @@ def _validate_reference_urls(urls, timeout=5):

# Sphinx gallery configuration
sphinx_gallery_conf = {
'examples_dirs': '../../examples',
'gallery_dirs': 'auto_examples',
'within_subsection_order': 'NumberOfCodeLinesSortKey',
'reference_url': _validate_reference_urls(_reference_urls),
'default_thumb_file': os.path.join(os.path.dirname(__file__), '..', '_static', 'trx_logo.png'),
'examples_dirs': '../../examples',
'gallery_dirs': 'auto_examples',
'within_subsection_order': 'NumberOfCodeLinesSortKey',
'reference_url': _validate_reference_urls(_reference_urls),
'default_thumb_file': os.path.join(os.path.dirname(__file__), '..', '_static', 'trx_logo.png'),
}
111 changes: 111 additions & 0 deletions trx/tests/test_memmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,117 @@ def test__ensure_little_endian_big_endian_input():
assert result[0] == 0x12345678


def test_load_zip64_with_extra_fields():
"""Test loading ZIP64 files where both local and CD headers have extra fields.

Rust and other tools always write ZIP64 extended information (extra field
ID 0x0001, 20 bytes: 4-byte tag+size + 8-byte orig + 8-byte comp) in both
local file headers and central directory entries, even for small files.
This ensures the data offset is computed correctly by reading the local
header's extra_len rather than assuming a fixed layout.
"""
positions = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype=np.float32)
offsets = np.array([0, 2], dtype=np.uint64)
header = {
"DIMENSIONS": [10, 10, 10],
"VOXEL_TO_RASMM": np.eye(4).tolist(),
"NB_VERTICES": 2,
"NB_STREAMLINES": 1,
}

def make_zip64_extra(orig_size, comp_size):
data = struct.pack("<QQ", orig_size, comp_size)
return struct.pack("<HH", 0x0001, len(data)) + data

with tempfile.TemporaryDirectory() as tmp_dir:
trx_path = os.path.join(tmp_dir, "test_zip64.trx")

with open(trx_path, "wb") as f:
local_info = []

for name, data in [
("header.json", json.dumps(header).encode()),
("positions.3.float32", positions.astype("<f4").tobytes()),
("offsets.uint64", offsets.astype("<u8").tobytes()),
]:
offset = f.tell()
fname = name.encode()
crc = zipfile.crc32(data)
# ZIP64 extended info in local header (20 bytes)
extra = make_zip64_extra(len(data), len(data))
f.write(
struct.pack(
"<4sHHHHHIIIHH",
b"PK\x03\x04",
45, # version needed: ZIP64
0,
0,
0,
0,
crc,
len(data),
len(data),
len(fname),
len(extra),
)
)
f.write(fname)
f.write(extra)
f.write(data)
local_info.append((name, offset, crc, len(data)))

cd_start = f.tell()
for name, offset, crc, size in local_info:
fname = name.encode()
# ZIP64 extended info in central directory entry (20 bytes)
extra = make_zip64_extra(size, size)
f.write(
struct.pack(
"<4sHHHHHHIIIHHHHHII",
b"PK\x01\x02",
45, # version made by: ZIP64
45, # version needed: ZIP64
0,
0,
0,
0,
crc,
size,
size,
len(fname),
len(extra),
0,
0,
0,
0,
offset,
)
)
f.write(fname)
f.write(extra)

cd_size = f.tell() - cd_start
f.write(
struct.pack(
"<4sHHHHIIH",
b"PK\x05\x06",
0,
0,
len(local_info),
len(local_info),
cd_size,
cd_start,
0,
)
)

trx = tmm.load_from_zip(trx_path)
np.testing.assert_array_almost_equal(trx.streamlines._data, positions)
assert trx.header["NB_VERTICES"] == 2
assert trx.header["NB_STREAMLINES"] == 1
trx.close()


def test_load_zip_with_local_header_extra_field():
"""Test loading ZIP where local header has extra field not in central dir.

Expand Down
Loading