mirror of
https://github.com/torarnv/sparsebundlefs.git
synced 2026-02-26 18:35:50 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user