Skip to content

Commit

Permalink
Fix unaligned access to zip data. There's still a corner case where i…
Browse files Browse the repository at this point in the history
…t could fail (if we do not reach the directory signature on the first try, we move only one byte backward) but it seems fine as far as I could test so far. #190
  • Loading branch information
ColinPitrat committed Mar 31, 2021
1 parent b1aa955 commit 4402e29
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ namespace zip
}
pbPtr = pbGPBuffer + (256 - 22); // pointer to end of central directory (under ideal conditions)
while (pbPtr != static_cast<byte *>(pbGPBuffer)) {
if (*reinterpret_cast<dword *>(pbPtr) == 0x06054b50) { // check for end of central directory signature
if (*reinterpret_cast<word *>(pbPtr) == 0x4b50 && *reinterpret_cast<word *>(pbPtr+2) == 0x0605) { // check for end of central directory signature
wCentralDirEntries = *reinterpret_cast<word *>(pbPtr + 10);
wCentralDirSize = *reinterpret_cast<word *>(pbPtr + 12);
dwCentralDirPosition = *reinterpret_cast<dword *>(pbPtr + 16);
dwCentralDirPosition = *(reinterpret_cast<word *>(pbPtr + 16)) + (*(reinterpret_cast<word *>(pbPtr + 18)) << 16);
break;
}
pbPtr--; // move backwards through buffer
Expand Down

0 comments on commit 4402e29

Please sign in to comment.