[GM-commit] GraphicsMagick: WriteBlobFile: Properly handle a short read.
Swiss army knife of image processing
Brought to you by:
bfriesen
From: GraphicsMagick C. <gra...@li...> - 2015-07-04 23:29:15
|
changeset 0901e0f11e5f in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=0901e0f11e5f summary: WriteBlobFile: Properly handle a short read. diffstat: ChangeLog | 2 ++ magick/blob.c | 53 +++++++++++++++++++++++++++-------------------------- www/Changelog.html | 1 + 3 files changed, 30 insertions(+), 26 deletions(-) diffs (116 lines): diff -r 5639afed647d -r 0901e0f11e5f ChangeLog --- a/ChangeLog Sat Jul 04 16:22:38 2015 -0500 +++ b/ChangeLog Sat Jul 04 18:29:03 2015 -0500 @@ -1,5 +1,7 @@ 2015-07-04 Bob Friesenhahn <bfr...@si...> + * magick/blob.c (WriteBlobFile): Properly handle short read. + * patches: Added directory of patches which may be useful when integrating new versions of 3rd-party programs or libraries into the VisualMagick build. diff -r 5639afed647d -r 0901e0f11e5f magick/blob.c --- a/magick/blob.c Sat Jul 04 16:22:38 2015 -0500 +++ b/magick/blob.c Sat Jul 04 18:29:03 2015 -0500 @@ -4440,49 +4440,49 @@ { int file; - - MagickStatStruct_t - attributes; - - unsigned char - *buffer; - - size_t - length; - - size_t - count; - - ssize_t - result; - - register size_t - i; MagickPassFail - status; - - status=MagickFail; + status=MagickFail; + if (MagickConfirmAccess(FileReadConfirmAccessMode,filename, &image->exception) == MagickFail) return MagickFail; file=open(filename,O_RDONLY | O_BINARY,0777); if (file != -1) { + MagickStatStruct_t + attributes; + /* st_size has type off_t */ if ((MagickFstat(file,&attributes) == 0) && (attributes.st_size == (off_t) ((size_t) attributes.st_size)) && (attributes.st_size > (off_t) ((size_t) 0))) { + unsigned char + *buffer; + + size_t + length; + + register size_t + i; + + unsigned int + count; + length=(size_t) attributes.st_size; - count = 32768; + count = 32768U; if (count > length) - count = length; + count = (unsigned int) length; buffer=MagickAllocateMemory(unsigned char *,count); + i=0; if (buffer != (unsigned char *) NULL) { - for (i=0; i < length; i+=count) + ssize_t + result; + + for (i=0; i < length; i+=result) { result=read(file,buffer,count); if (result <= 0) @@ -4492,7 +4492,8 @@ } MagickFreeMemory(buffer); } - status = MagickPass; + if (i == length) + status = MagickPass; } (void) close(file); } @@ -4858,4 +4859,4 @@ blob=CloneBlobInfo(image->blob); DestroyBlob(image); image->blob=blob; -} \ No newline at end of file +} diff -r 5639afed647d -r 0901e0f11e5f www/Changelog.html --- a/www/Changelog.html Sat Jul 04 16:22:38 2015 -0500 +++ b/www/Changelog.html Sat Jul 04 18:29:03 2015 -0500 @@ -38,6 +38,7 @@ <p>2015-07-04 Bob Friesenhahn <<a class="reference external" href="mailto:bfriesen%40simple.dallas.tx.us">bfriesen<span>@</span>simple<span>.</span>dallas<span>.</span>tx<span>.</span>us</a>></p> <blockquote> <ul class="simple"> +<li>magick/blob.c (WriteBlobFile): Properly handle short read.</li> <li>patches: Added directory of patches which may be useful when integrating new versions of 3rd-party programs or libraries into the VisualMagick build.</li> |