Re: Corrupt image when identify gif image
莫红波 <[email protected]> Fri, 20 Nov 2015 12:31:55 +0800
| Newsgroups | gmane.comp.video.graphicsmagick.bugs |
|---|---|
| Message-ID | <CACghtk2v5rBsu+mp38BHXVHk5m7HJjXtNRmKwNMiYmUbZiGcdw@mail.gmail.com> |
--===============3747443702971778137==
Content-Type: multipart/alternative; boundary=94eb2c035a1cf25b2d0524f15a84
--94eb2c035a1cf25b2d0524f15a84
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I find that some GIFs set an invalid value as transparent index such as
image->colors+1.
However,
```
/*
Read local colormap.
*/
colormap=3DMagickAllocateMemory(unsigned char *,3*image->colors);
if (colormap =3D=3D (unsigned char *) NULL)
{
MagickFreeMemory(global_colormap);
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
image);
}
if (ReadBlob(image,3*image->colors,(char *) colormap) !=3D
3*image->colors) // <------- BUG
{
MagickFreeMemory(global_colormap);
MagickFreeMemory(colormap);
ThrowReaderException(CorruptImageError,InsufficientImageDataInFile,image);
}
```
On Fri, Oct 9, 2015 at 1:04 PM, =E8=8E=AB=E7=BA=A2=E6=B3=A2 <hongbo.mo@upai=
.com> wrote:
>
> The command:
>
> gm identify test.gif
>
> The output in terminal:
>
> gm identify: Corrupt image (test.gif)
>
> However, Imagemagicks does well.
>
> So, I gdb GM and IM and then I found the difference.
>
> In GM.1.3.22 coders/gif.c:
>
> 1011 if (opacity >=3D (long) image->colors)
> 1012 image->colors=3Dopacity+1;
>
> In IM:
>
> 1259 if (opacity >=3D (ssize_t) image->colors)
> 1260 opacity=3D(-1);
>
> ------
>
> This difference will cause mistakes when allocating local colormaps.
> Moreover I scaned spec-gif89a.txt
> <http://www.w3.org/Graphics/GIF/spec-gif89a.txt> and didn't find anything
> about this. So I'm not sure whether it's a bug.
>
>
> image URL: http://bigfile.b0.upaiyun.com/test.gif
>
>
>
>
>
>
>
>
>
>
--94eb2c035a1cf25b2d0524f15a84
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><p style=3D"font-size:12.8px;margin:1.2em 0px!important"><=
span style=3D"font-size:12.8px">I find that some GIFs set an invalid value =
as transparent index such as image->colors+1.</span><br></p><p style=3D"=
font-size:12.8px;margin:1.2em 0px!important">However,</p><div><div><font co=
lor=3D"#000000">```=C2=A0</font></div><div><font color=3D"#000000">=C2=A0/*=
</font></div><div><font color=3D"#000000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 Read local colormap.</font></div><div><font color=3D"#000000">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 */</font></div><div><font color=3D"#000000">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 colormap=3DMagickAllocateMemory(unsigned char *,3*image-&=
gt;colors);</font></div><div><font color=3D"#000000">=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (colormap =3D=3D (unsigned char *) NULL)</font></div><div><font c=
olor=3D"#000000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {</font></div><div><fon=
t color=3D"#000000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MagickFreeMem=
ory(global_colormap);</font></div><div><font color=3D"#000000">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ThrowReaderException(ResourceLimitError,Mem=
oryAllocationFailed,</font></div><div><font color=3D"#000000">=C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0image);</font></div><div><font color=3D"#000=
000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</font></div><div><font color=3D"#=
000000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ReadBlob(image,3*image->colors,(=
char *) colormap) !=3D 3*image->colors) =C2=A0 =C2=A0// <------- =C2=
=A0BUG</font></div><div><font color=3D"#000000">=C2=A0 =C2=A0 =C2=A0 {</fon=
t></div><div><font color=3D"#000000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 MagickFree=
Memory(global_colormap);</font></div><div><font color=3D"#000000">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 MagickFreeMemory(colormap);</font></div><div><font col=
or=3D"#000000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 ThrowReaderException(CorruptImag=
eError,InsufficientImageDataInFile,image);</font></div><div><font color=3D"=
#000000">=C2=A0 =C2=A0 =C2=A0 }</font></div></div><div>```</div><div><br></=
div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Fri, Oct 9=
, 2015 at 1:04 PM, =E8=8E=AB=E7=BA=A2=E6=B3=A2 <span dir=3D"ltr"><<a hre=
f=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>>=
;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p=
x 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border=
-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_qu=
ote"><br><div dir=3D"ltr"><div><div class=3D"h5">The command:<div>=C2=A0=C2=
=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 gm identify test.gif</div><div><b=
r></div><div>The output in terminal:</div><div><br></div><div>=C2=A0 =C2=A0=
=C2=A0 =C2=A0 gm identify: Corrupt image (test.gif)<br></div><div><br></di=
v><div>However, Imagemagicks does well.</div><div><br></div><div>So, I gdb =
GM and IM and then I found the difference.</div><div><br></div><div>In GM.1=
.3.22 coders/gif.c:</div><div><br></div><div><div>=C2=A0 =C2=A0 =C2=A01011 =
=C2=A0 =C2=A0 if (opacity >=3D (long) image->colors)</div><div>=C2=A0=
=C2=A0 =C2=A01012 =C2=A0 =C2=A0 =C2=A0 image->colors=3Dopacity+1;</div>=
</div><div><br></div><div>In IM:</div><div><br></div><div>=C2=A0 =C2=A0 =C2=
=A01259 =C2=A0 =C2=A0 if (opacity >=3D (ssize_t) image->colors)</div>=
<div>=C2=A0 =C2=A0 =C2=A01260 =C2=A0 =C2=A0 =C2=A0 opacity=3D(-1);</div><di=
v><br></div><div>------</div><div><br></div><div>This difference will cause=
mistakes when allocating local colormaps. Moreover I scaned=C2=A0<a href=
=3D"http://www.w3.org/Graphics/GIF/spec-gif89a.txt" target=3D"_blank">spec-=
gif89a.txt</a>=C2=A0and didn't find anything about this. So I'm not=
sure whether it's a bug.</div><div><br></div><div><br></div></div></di=
v><div>image URL: =C2=A0<a href=3D"http://bigfile.b0.upaiyun.com/test.gif" =
target=3D"_blank">http://bigfile.b0.upaiyun.com/test.gif</a></div><div><br>=
</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br>=
</div><div><br></div><div><br></div></div>
</div><br></div>
</blockquote></div><br></div></div>
--94eb2c035a1cf25b2d0524f15a84--
--===============3747443702971778137==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
--===============3747443702971778137==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Graphicsmagick-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-bugs
--===============3747443702971778137==--