On 2014-12-15 16:32:32, TSIBLEY wrote:
Show quoted text> On Thu Dec 11 14:14:19 2014, SREZIC wrote:
> > If you need a quick fix, then you can make the
> > variable readonly (e.g. using the Readonly or Readonly::XS module);
> > in
> > this case the code will die() instead of segfaulting.
>
> On a closer inspection, this workaround doesn't really work. It does
> prevent the segfault on the tiff data I provided, but it also throws a
> "Modification of a read-only variable" exception on *any* image data I
> throw at image_info(). :/
Well, and using Internals::SvREADONLY() also does not help --- valid images work again, but it cannot trap the segfault...
A workaround is to use either IO::Scalar or IO::String instead of perl's builtin IO scalar handling. And of both alternatives, IO::Scalar seems to be faster than IO::String.
I made an experimental branch which you can find here:
git clone
https://github.com/eserte/image-info.git -b XXX-RT100847
Make sure that IO::Scalar is installed. With this branch, your test script does not segfault anymore, output is:
Unrecognised fieldtype 64704, skipping
from file: $VAR1 = {
'error' => 'short read (2/0) at pos 2348827295 at /home/e/eserte/src/CPAN.local/Image-Info/blib/lib/Image/Info/TIFF.pm line 42.
'
};
Unrecognised fieldtype 64704, skipping
from ref: $VAR1 = {
'error' => 'short read (2/0) at pos 1503418 at /home/e/eserte/src/CPAN.local/Image-Info/blib/lib/Image/Info/TIFF.pm line 42.
'
};
I still have to think about a real solution. Maybe all read(), seek() etc. operations need to be protected in the scalar ref case, i.e. there has to be a check that the string buffer is not exceeded.
Regards,
Slaven