unzip: return uncompressed size in `filesize', and print it.
PATCH 1/1 unzip: return uncompressed size in `filesize', and print it.
The unzip command did not provide a way for the caller to get any information about the uncompressed size. To make it better usable in scripts, we now store the uncompressed size in the `filesize' variable, like we do when for example loading a file over the network or when reading it from a file system. Following that analogy, it is only consequent to also print the size.
--- common/cmd_mem.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
common/cmd_mem.c +9 -1
@@ -1212,6 +1212,8 @@ int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {unsigned long src, dst;unsigned long src_len = ~0UL , dst_len = ~0UL ; +int rc; +char buf[32 ];switch (argc) {case 4 :
@@ -1225,7 +1227,13 @@ int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return cmd_usage(cmdtp); } -return !!gunzip ((void *) dst, dst_len, (void *) src, &src_len); + rc =gunzip ((void *) dst, dst_len, (void *) src, &src_len); + +printf ("Uncompressed size: %ld = 0x%lX\n" , src_len, src_len); +sprintf (buf,"%lX" , src_len); +setenv ("filesize" , buf); + +return !!rc; }#endif /* CONFIG_CMD_UNZIP */
Signature · 1 line
1.7.4
PATCH 1/1 unzip: return uncompressed size in `filesize', and print it.
Hi Wolfgang,
common/cmd_mem.c int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 1236
Quoted 8 lines
common/cmd_mem.c +7
-1-return !!gunzip ((void *) dst, dst_len, (void *) src, &src_len); + rc =gunzip ((void *) dst, dst_len, (void *) src, &src_len); + +printf ("Uncompressed size: %ld = 0x%lX\n" , src_len, src_len); +sprintf (buf,"%lX" , src_len); +setenv ("filesize" , buf); + +return !!rc;
What about:
if (rc)
return rc;
printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len); sprintf(buf, "%lX", src_len);setenv("filesize", buf);
return 0;
This will prevent printing and setting of bogus values when an invalid or overly large image is unzipped.
Best,
Peter
PATCH 1/1 unzip: return uncompressed size in `filesize', and print it.
Dear Peter Tyser,
Quoted 18 lines · In message <1297443439.965.1208.camel@petert> you wrote:
common/cmd_mem.c int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 1236
Quoted 9 lines
common/cmd_mem.c +7
-1-return !!gunzip ((void *) dst, dst_len, (void *) src, &src_len); + rc =gunzip ((void *) dst, dst_len, (void *) src, &src_len); + +printf ("Uncompressed size: %ld = 0x%lX\n" , src_len, src_len); +sprintf (buf,"%lX" , src_len); +setenv ("filesize" , buf); + +return !!rc;What about:
if (rc)return rc;
printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);sprintf(buf, "%lX", src_len);setenv("filesize", buf);
Quoted 5 lines
return 0;
This will prevent printing and setting of bogus values when an invalid or overly large image is unzipped.
Good point, will fix. Thanks!
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de HANDLE WITH EXTREME CARE: This Product Contains Minute Electrically Charged Particles Moving at Velocities in Excess of Five Hundred Million Miles Per Hour.
PATCH v2 1/1 unzip: return uncompressed size in `filesize', and print it.
In reply to Wolfgang DenkThe unzip command did not provide a way for the caller to get any information about the uncompressed size. To make it better usable in scripts, we now store the uncompressed size in the `filesize' variable, like we do when for example loading a file over the network or when reading it from a file system. Following that analogy, it is only consequent to also print the size.
---
v2: return early in case of errors,
set 'filesize' only on success.
This also avoids the new 'rc' variable.
Courtesy to Peter Tyser for pointing out.
common/cmd_mem.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
common/cmd_mem.c +9 -1
@@ -1212,6 +1212,7 @@ int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {unsigned long src, dst;unsigned long src_len = ~0UL , dst_len = ~0UL ; +char buf[32 ];switch (argc) {case 4 :
@@ -1225,7 +1226,14 @@ int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return cmd_usage(cmdtp); } -return !!gunzip ((void *) dst, dst_len, (void *) src, &src_len); +if (gunzip ((void *) dst, dst_len, (void *) src, &src_len) !=0 ) +return 1 ; + +printf ("Uncompressed size: %ld = 0x%lX\n" , src_len, src_len); +sprintf (buf,"%lX" , src_len); +setenv ("filesize" , buf); + +return 0 ; }#endif /* CONFIG_CMD_UNZIP */
Signature · 1 line
1.7.4
Wolfgang Denk
AppliedPATCH v2 1/1 unzip: return uncompressed size in `filesize', and print it.
Dear Wolfgang Denk,
Quoted 8 lines · In message <[email protected]> you wrote:
The unzip command did not provide a way for the caller to get any information about the uncompressed size. To make it better usable in scripts, we now store the uncompressed size in the `filesize' variable, like we do when for example loading a file over the network or when reading it from a file system. Following that analogy, it is only consequent to also print the size.
Signed-off-by Wolfgang Denk <[email protected]>
Quoted 8 lines
---
v2: return early in case of errors,
set 'filesize' only on success.
This also avoids the new 'rc' variable.
Courtesy to Peter Tyser for pointing out.common/cmd_mem.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Real computer scientists despise the idea of actual hardware. Hard- ware has limitations, software doesn't. It's a real shame that Turing machines are so poor at I/O.