@@ -193,6 +193,12 @@ namespace appimage::update {
193
193
assertIfstreamGood (ifs);
194
194
195
195
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
+
196
202
std::streamsize bytesRead = 0 ;
197
203
198
204
auto bytesLeftInChunk = std::min (chunkSize, (fileSize - totalBytesRead));
@@ -250,11 +256,12 @@ namespace appimage::update {
250
256
}
251
257
};
252
258
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
+ }
258
265
259
266
// check whether one of the sections that must be skipped are in the current chunk, and if they
260
267
// are, skip those sections in the current and future sections
@@ -266,6 +273,9 @@ namespace appimage::update {
266
273
readBytes (bytesLeftInChunk);
267
274
}
268
275
276
+ // make sure the buffer has the right size
277
+ buffer.resize (bytesRead);
278
+
269
279
// update hash with data from buffer
270
280
digest.add (buffer);
271
281
}
0 commit comments