Skip to content

MAT_v5: ZlibError when reading valid compressed v5 files saved by MATLAB on Windows (PCWIN64) #242

@ktitimbo

Description

@ktitimbo

ZlibError when reading valid compressed v5 files saved by MATLAB on Windows (PCWIN64)

Description

Reading a valid MATLAB v5 .mat file saved on Windows (platform tag PCWIN64) fails with a
CodecZlib.ZlibError: incorrect header check (code: -3) when calling keys(), read(), or
matread(). The file loads correctly in scipy.io and in MATLAB itself.

To reproduce

using MAT
file = matopen("file.mat")
keys(file)   # throws ZlibError

Error

ERROR: CodecZlib.ZlibError("incorrect header check (code: -3)")
Stacktrace:
  [1] changemode!(stream::TranscodingStreams.TranscodingStream{CodecZlib.ZlibDecompressor, IOStream}, ...)
    @ TranscodingStreams .../TranscodingStreams/src/stream.jl:794
  [2] callprocess(...)
    @ TranscodingStreams .../TranscodingStreams/src/stream.jl:707
  [3] fillbuffer(...)
    @ TranscodingStreams .../TranscodingStreams/src/stream.jl:624
  [4] read_element(f::TranscodingStreams.TranscodingStream{...}, swap_bytes::Bool, ...)
    @ MAT.MAT_v5 .../MAT/src/MAT_v5.jl:135
  [5] getvarnames(matfile::MAT.MAT_v5.Matlabv5File)
    @ MAT.MAT_v5 .../MAT/src/MAT_v5.jl:446
  [6] keys(...)
    @ MAT.MAT_v5 .../MAT/src/MAT_v5.jl:456

File info

Header string as reported by scipy.io:

MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Tue Jun  2 16:59:08 2026

HDF5.ishdf5(filename) returns false, confirming the file is genuine v5, not v7.3.

The file contains:

  • several double scalars (1×1)
  • uint16 arrays of shape 540×2560×10
  • a 1×1 string variable

scipy.io reads all numeric variables correctly but silently drops the string variable.
MAT.jl fails at the keys() call before any variable is read, suggesting the issue is in
the compressed block header parsing in MAT_v5.jl, not in the variable data itself.

Expected behaviour

keys(), haskey(), and read() should work on any valid MATLAB v5 file regardless of
platform or compression implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions