Skip to content

Commit 8b9842c

Browse files
committed
Fix new hashing helper
Fixes a copy-paste error. Also, now the size of the buffer containing the bytes read from the file should be correct.
1 parent e9aa6c3 commit 8b9842c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/appimage.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ namespace appimage::update {
193193
assertIfstreamGood(ifs);
194194

195195
while (ifs) {
196+
// in case we read less bytes than the chunk size, we resize the vector to the number of bytes read
197+
// we have to reset this upon the next iteration
198+
// this should be a no-op when the size has not changed, and should not be necessary, as the only time
199+
// we receive less bytes than requested should be the final read call
200+
buffer.resize(chunkSize);
201+
196202
std::streamsize bytesRead = 0;
197203

198204
auto bytesLeftInChunk = std::min(chunkSize, (fileSize - totalBytesRead));
@@ -250,11 +256,12 @@ namespace appimage::update {
250256
}
251257
};
252258

253-
// check whether one of the sections that must be skipped are in the current chunk, and if they
254-
// are, skip those sections in the current and future sections
255-
// TODO: fix narrowing
256-
checkSkipSection(static_cast<std::streamsize>(sigOffset), static_cast<std::streamsize>(sigLength));
257-
checkSkipSection(static_cast<std::streamsize>(keyOffset), static_cast<std::streamsize>(keyLength));
259+
// check whether bytes must be skipped from previous sections
260+
if (bytesToSkip > 0) {
261+
auto bytesToSkipInCurrentChunk = std::min(chunkSize, bytesToSkip);
262+
skipBytes(bytesToSkipInCurrentChunk);
263+
bytesToSkip -= bytesToSkipInCurrentChunk;
264+
}
258265

259266
// check whether one of the sections that must be skipped are in the current chunk, and if they
260267
// are, skip those sections in the current and future sections
@@ -266,6 +273,9 @@ namespace appimage::update {
266273
readBytes(bytesLeftInChunk);
267274
}
268275

276+
// make sure the buffer has the right size
277+
buffer.resize(bytesRead);
278+
269279
// update hash with data from buffer
270280
digest.add(buffer);
271281
}

0 commit comments

Comments
 (0)