Skip to content

Commit d5058e8

Browse files
committed
Fix Issue #169 SparseMatrixCSC illegal buffers
1 parent 82c289b commit d5058e8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/MAT_v5.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,19 @@ function read_sparse(f::IO, swap_bytes::Bool, dimensions::Vector{Int32}, flags::
244244
pr = complex_array(pr, read_data(f, swap_bytes))
245245
end
246246
end
247-
247+
if length(ir) > length(pr)
248+
# Fix for Issue #169, xref https://github.com/JuliaLang/julia/pull/40523
249+
#=
250+
# The following expression must be obeyed according to
251+
# https://github.com/JuliaLang/julia/blob/b3e4341d43da32f4ab6087230d98d00b89c8c004/stdlib/SparseArrays/src/sparsematrix.jl#L86-L90
252+
@debug "SparseMatrixCSC" m n jc ir pr
253+
@debug "SparseMatrixCSC check " length(jc) n+1 jc[end]-1 length(ir) length(pr) begin
254+
length(jc) == n + 1 && jc[end] - 1 == length(ir) == length(pr)
255+
end
256+
=#
257+
# Truncate rowvals (ir) to the be the same length as the non-zero elements (pr)
258+
resize!(ir, length(pr))
259+
end
248260
SparseMatrixCSC(m, n, jc, ir, pr)
249261
end
250262

0 commit comments

Comments
 (0)