From bfe906f853da879e61d19da4b18bdb4083a5d317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 7 Oct 2012 22:27:36 +0200 Subject: [PATCH] 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. --- sparsebundlefs.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sparsebundlefs.cpp b/sparsebundlefs.cpp index d5a152d..d1bb5e2 100644 --- a/sparsebundlefs.cpp +++ b/sparsebundlefs.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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(length - bytes_read), + SB_DATA->band_size - band_offset); char *band_name; asprintf(&band_name, "%s/bands/%llx", SB_DATA->path, band_number);