Skip to content

Fix load_npz single-variable skip over extra fields#181

Merged
JohanMabille merged 1 commit into
xtensor-stack:masterfrom
realwangzhichao:dev
Jun 19, 2026
Merged

Fix load_npz single-variable skip over extra fields#181
JohanMabille merged 1 commit into
xtensor-stack:masterfrom
realwangzhichao:dev

Conversation

@realwangzhichao

Copy link
Copy Markdown
Contributor

Summary

This PR fixes xt::load_npz(filename, search_varname) when scanning NPZ files that contain a non-zero ZIP local header extra_field_len.

Previously, when the current array name did not match search_varname, the code skipped only entry.compressed_size. This left the stream positioned inside the current entry's extra field for NPZ files with extra_field_len > 0, causing subsequent local headers to be misread and later arrays to be reported as missing.

The fix reuses extract_zip64_compressed_size(stream, entry), which already consumes the extra field and handles ZIP64 size metadata, then seeks over the compressed payload.

Validation

I tested this change with a NumPy-generated .npz file whose local ZIP entries each have extra_field_len = 20.

Before this fix, reading an array that appears after the first entry failed:

xt::load_npz<float>(filename, "body_quat_w");

@JohanMabille

Copy link
Copy Markdown
Member

Thanks for the fix. The CI needs to be fixed before we can merge this one, I'm working on it.

@JohanMabille

Copy link
Copy Markdown
Member

Thanks again!

@JohanMabille JohanMabille merged commit f1077b6 into xtensor-stack:master Jun 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants