summaryrefslogtreecommitdiff
path: root/libsparse/backed_block.cpp
diff options
context:
space:
mode:
authorHyeongseok Kim <hyeongseok@gmail.com>2020-08-10 12:11:57 +0900
committerHyeongseok Kim <hyeongseok@gmail.com>2020-08-11 08:34:28 +0900
commite8d02c50d76e278f91455bd90e1db2ae79eac035 (patch)
treee768a72f0edf6caf3055cd9d7fcb1ef4c032cf1e /libsparse/backed_block.cpp
parent52c8422ea19b5719f8128b85fb01d985bd415c46 (diff)
libsparse: Fix overflow of merged sparse chunk length
Merging sparse chunk can make sparse map block bigger than 4GiB, that can't be covered by unsigned integer type. Fix this by changing unsigned int to uint64_t type. Test: sparse build Bug: 162808120 Change-Id: Id4d3f88f9d531c25c3937c99b2c81efb915605ee Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com> Cc: hyeongseok.kim <hyeongseok.kim@lge.com>
Diffstat (limited to 'libsparse/backed_block.cpp')
-rw-r--r--libsparse/backed_block.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/libsparse/backed_block.cpp b/libsparse/backed_block.cpp
index f3d8022ac..6229e7c6e 100644
--- a/libsparse/backed_block.cpp
+++ b/libsparse/backed_block.cpp
@@ -25,7 +25,7 @@
struct backed_block {
unsigned int block;
- unsigned int len;
+ uint64_t len;
enum backed_block_type type;
union {
struct {
@@ -60,7 +60,7 @@ struct backed_block* backed_block_iter_next(struct backed_block* bb) {
return bb->next;
}
-unsigned int backed_block_len(struct backed_block* bb) {
+uint64_t backed_block_len(struct backed_block* bb) {
return bb->len;
}
@@ -270,7 +270,7 @@ static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb)
}
/* Queues a fill block of memory to be written to the specified data blocks */
-int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, unsigned int len,
+int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, uint64_t len,
unsigned int block) {
struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
if (bb == nullptr) {
@@ -287,7 +287,7 @@ int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val,
}
/* Queues a block of memory to be written to the specified data blocks */
-int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned int len,
+int backed_block_add_data(struct backed_block_list* bbl, void* data, uint64_t len,
unsigned int block) {
struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
if (bb == nullptr) {
@@ -305,7 +305,7 @@ int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned in
/* Queues a chunk of a file on disk to be written to the specified data blocks */
int backed_block_add_file(struct backed_block_list* bbl, const char* filename, int64_t offset,
- unsigned int len, unsigned int block) {
+ uint64_t len, unsigned int block) {
struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
if (bb == nullptr) {
return -ENOMEM;
@@ -322,7 +322,7 @@ int backed_block_add_file(struct backed_block_list* bbl, const char* filename, i
}
/* Queues a chunk of a fd to be written to the specified data blocks */
-int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, unsigned int len,
+int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, uint64_t len,
unsigned int block) {
struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
if (bb == nullptr) {