Subject: | Attempt to extend stack by negative value causes panic with perl 5.23.4 |
[_get_anonymous_color_histo in Imager.xs][1] calls [_get_anonymous_color_histo in image.c][2].
The latter routine [returns -1][3] if the number of colors exceeds the `maxc` parameter.
In Imager.xs, that return value is used to [extend the stack][4].
Using `EXTEND` with a negative amount causes a recently committed check to be hit in [`scope.c`][5] (see also [diff][6]).
This causes a failure in [t/100-base/030-count.t][7]:
@colour_usage = $im->getcolorusage(maxcolors => 2);
is(@colour_usage, 0, 'test overflow check');
The invocation of `getcolorusage` with the maxcolors argument causes a panic, and the test is not reached.
Arguably, the underlying `EXTEND` with a negative argument has always been wrong. I have not investigated the behavior of `EXTEND` through releases, but, logically, adjusting the return stack by a negative value seems like it could not have a legitimate use.
I will submit a patch when I get a chance to look at this again.
Thank you.
-- Sinan
[1]: https://metacpan.org/source/TONYC/Imager-1.003/Imager.xs#L2668
[2]: https://metacpan.org/source/TONYC/Imager-1.003/image.c#L1273
[3]: https://metacpan.org/source/TONYC/Imager-1.003/image.c#L1303
[4]: https://metacpan.org/source/TONYC/Imager-1.003/Imager.xs#L2677
[5]: http://perl5.git.perl.org/perl.git/commit/6768377c79109b7124f0c8a4e3677982689d9f49?f=scope.c
[6]: http://perl5.git.perl.org/perl.git/blobdiff/73e8ff0004522621dfb42f01966853b51d5522a6..6768377c79109b7124f0c8a4e3677982689d9f49:/scope.c
[7]: https://metacpan.org/source/TONYC/Imager-1.003/t/100-base/030-countc.t#L48