Skip to content

Commit

Permalink
Merge pull request #34 from yuyichao/align
Browse files Browse the repository at this point in the history
Fix wrong use of reinterpret
  • Loading branch information
fhs authored May 17, 2017
2 parents 4577d76 + b90db13 commit 46542e4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ZipFile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ function mtime(f::@compat Union{ReadableFile, WritableFile})
_mtime(f.dostime, f.dosdate)
end

"Load a little endian `UInt32` from a `UInt8` vector `b` starting from index `i`"
function getindex_u32le(b::Vector{UInt8}, i)
b0 = UInt32(b[i])
b1 = UInt32(b[i + 1])
b2 = UInt32(b[i + 2])
b3 = UInt32(b[i + 3])
return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0
end

function _find_enddiroffset(io::IO)
seekend(io)
filesize = position(io)
Expand All @@ -262,7 +271,7 @@ function _find_enddiroffset(io::IO)
seek(io, n)
b = read(io, UInt8, k)
for i in 1:k-3
if htol(reinterpret(UInt32, b[i:i+3]))[1] == _EndCentralDirSig
if getindex_u32le(b, i) == _EndCentralDirSig
offset = n+i-1
break
end
Expand Down

0 comments on commit 46542e4

Please sign in to comment.