Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions image-android-sparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static int android_sparse_generate(struct image *image)
off_t offset;
unsigned int i;
uint32_t *buf, *zeros, crc32 = 0;
uint32_t max_raw_blocks = (UINT32_MAX - sizeof(struct sparse_chunk_header)) / sparse->block_size;
struct stat s;

memset(&header, 0, sizeof(header));
Expand Down Expand Up @@ -161,7 +162,6 @@ static int android_sparse_generate(struct image *image)
So all start and end of all extents must be aligned accordingly. The
extents may overlap now, so merge them if necessary. */
for (extent = 0; extent < extent_count; ++extent) {
size_t size, max;
int j;

extents[extent].start = extents[extent].start / sparse->block_size *
Expand All @@ -179,16 +179,6 @@ static int android_sparse_generate(struct image *image)
extents[extent].start = 0;
extents[extent].end = 0;
}

/* TODO: split extents that are too big */
max = (~(uint32_t)0) - sizeof(struct sparse_chunk_header);
size = extents[extent].end - extents[extent].start;
if (size > max) {
image_error(image, "extents size %llu larger and supported maximum %llu.\n",
(unsigned long long)size, (unsigned long long)max);
ret = -EINVAL;
goto out;
}
}

out_fd = open_file(image, imageoutfile(image), O_TRUNC);
Expand Down Expand Up @@ -292,7 +282,8 @@ static int android_sparse_generate(struct image *image)
}
chunk_header.blocks++;
} else {
if (chunk_header.chunk_type != SPARSE_RAW) {
if (chunk_header.chunk_type != SPARSE_RAW ||
chunk_header.blocks >= max_raw_blocks) {
header.input_chunks++;
ret = flush_header(image, out_fd, &chunk_header, pos);
if (ret < 0)
Expand Down