Fix reads across band boundaries

If a read was requested at an offset just before the end of a band,
with a length sufficiently large to cross over to the next band, we
would pad the remaining space after the initial band with zeroes,
and never proceed to read the second band.

We now limit the size of each consecutive band read to the end of the
band, so that the while loop will correctly continue with the next
band if there's still more data to be read.
This commit is contained in:
Tor Arne Vestbø
2012-10-07 22:27:36 +02:00
parent c9e2a8ed53
commit bfe906f853

View File

@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <syslog.h>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
@@ -87,7 +88,8 @@ static int sparsebundle_read(const char *path, char *buffer, size_t length, off_
off_t band_number = (offset + bytes_read) / SB_DATA->band_size;
off_t band_offset = (offset + bytes_read) % SB_DATA->band_size;
ssize_t to_read = length - bytes_read;
ssize_t to_read = min(static_cast<off_t>(length - bytes_read),
SB_DATA->band_size - band_offset);
char *band_name;
asprintf(&band_name, "%s/bands/%llx", SB_DATA->path, band_number);