forked from len0rd/rockbox
sbtools: fix code to work with file larger than header indicated size
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30544 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
781d59ec62
commit
da44fd6f99
1 changed files with 10 additions and 4 deletions
|
|
@ -71,7 +71,6 @@ char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' };
|
||||||
|
|
||||||
/* globals */
|
/* globals */
|
||||||
|
|
||||||
size_t g_sz; /* file size */
|
|
||||||
uint8_t *g_buf; /* file content */
|
uint8_t *g_buf; /* file content */
|
||||||
#define PREFIX_SIZE 128
|
#define PREFIX_SIZE 128
|
||||||
char out_prefix[PREFIX_SIZE];
|
char out_prefix[PREFIX_SIZE];
|
||||||
|
|
@ -378,6 +377,14 @@ static void extract(unsigned long filesize)
|
||||||
if(sb_header->sec_hdr_size * BLOCK_SIZE != sizeof(struct sb_section_header_t))
|
if(sb_header->sec_hdr_size * BLOCK_SIZE != sizeof(struct sb_section_header_t))
|
||||||
bugp("Bad section header size");
|
bugp("Bad section header size");
|
||||||
|
|
||||||
|
if(filesize > sb_header->image_size * BLOCK_SIZE)
|
||||||
|
{
|
||||||
|
color(GREY);
|
||||||
|
printf("[Restrict file size from %lu to %d bytes]\n", filesize,
|
||||||
|
sb_header->image_size * BLOCK_SIZE);
|
||||||
|
filesize = sb_header->image_size * BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
color(BLUE);
|
color(BLUE);
|
||||||
printf("Basic info:\n");
|
printf("Basic info:\n");
|
||||||
color(GREEN);
|
color(GREEN);
|
||||||
|
|
@ -763,10 +770,9 @@ int main(int argc, const char **argv)
|
||||||
|
|
||||||
if(fstat(fd, &st) == -1)
|
if(fstat(fd, &st) == -1)
|
||||||
bugp("firmware stat() failed");
|
bugp("firmware stat() failed");
|
||||||
g_sz = st.st_size;
|
|
||||||
|
|
||||||
g_buf = xmalloc(g_sz);
|
g_buf = xmalloc(st.st_size);
|
||||||
if(read(fd, g_buf, g_sz) != (ssize_t)g_sz) /* load the whole file into memory */
|
if(read(fd, g_buf, st.st_size) != (ssize_t)st.st_size) /* load the whole file into memory */
|
||||||
bugp("reading firmware");
|
bugp("reading firmware");
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue