Imagick::queryFontMetrics faulty textWidth | Integer overflow | Debian 8 (Jessie) | Ubuntu 15.10
Posted: 2016-02-11T07:02:35-07:00
Hello,
I am migrating from Debian 7 to Debian 8 and Imagick::queryFontMetrics is sometimes returning faulty calculations for the textWidth and the boundingBox[x1] of individual characters, likely due to an integer overflow. My setup in Debian 7 is working just fine, my Debian 8 and Ubuntu 15.10 setup looks buggy. The faulty calculations are pretty much off by 33554430, which corresponds to two added up medium unsigned integers (3 bytes in length, maximum value == 16777215).
To reproduce, take the following font (RNS.ttf):
http://www.1001fonts.com/rns-font.html
queryFontMetrics for the character 'g':
Debian 8 and Ubuntu 15.10 (bogus results):
Another font example (GreatVibes-Regular.ttf), breaks for the letter 'u' in certain sizes:
https://github.com/google/fonts/tree/ma ... greatvibes
queryFontMetrics for the character 'u' in size 256:
Debian 8 and Ubuntu 15.10 (bogus results):
Size 72 looks fine for the GreatVibes font.
Here is my stack:
$ apt-cache policy libfreetype6
Debian 7 (wheezy): 2.4.9-1.1+deb7u3
Debian 8 (jessie): 2.5.2-3+deb8u1
Ubuntu 15.10: 2.5.2-4ubuntu2
I have tried installing some different freetype versions by hand, but with the same results.
$ apt-cache policy imagemagick
Debian 7 (wheezy): 8:6.7.7.10-5+deb7u3
Debian 8 (jessie): 8:6.8.9.9-5
Ubuntu 15.10: 8:6.8.9.9-5ubuntu2
I also tried with manual install of ImageMagick-6.9.2-6 with same results.
$ apt-cache policy php5-imagick
Debian 7 (wheezy): 3.1.0~rc1-1+b2
Debian 8 (jessie): 3.2.0~rc1-1
Ubuntu 15.10: 3.3.0~rc2-1
I have tried several imagick versions via PECL with same results.
I have tried looking at two font files in the above examples, opening them in fontforge. I wasn't able to find any abnormalities with the disobedient characters, but then again my fontforge knowledge is very poor.
I am migrating from Debian 7 to Debian 8 and Imagick::queryFontMetrics is sometimes returning faulty calculations for the textWidth and the boundingBox[x1] of individual characters, likely due to an integer overflow. My setup in Debian 7 is working just fine, my Debian 8 and Ubuntu 15.10 setup looks buggy. The faulty calculations are pretty much off by 33554430, which corresponds to two added up medium unsigned integers (3 bytes in length, maximum value == 16777215).
To reproduce, take the following font (RNS.ttf):
http://www.1001fonts.com/rns-font.html
queryFontMetrics for the character 'g':
Code: Select all
<?php
$image = new Imagick();
$fontDraw = new ImagickDraw();
$fontDraw->setFont('./RNS.ttf');
$fontDraw->setFontSize(72);
$fontMetrics = $image->queryFontMetrics($fontDraw, 'g', FALSE);
print_r($fontMetrics);
?>
Debian 8 and Ubuntu 15.10 (bogus results):
Debian 7 (correct results):Array
(
[characterWidth] => 72
[characterHeight] => 72
[ascender] => 70
[descender] => -31
[textWidth] => 33554469.1875
[textHeight] => 103
[maxHorizontalAdvance] => 61
[boundingBox] => Array
(
[x1] => -33554430.1875
[y1] => -0.09375
[x2] => 35
[y2] => 55.171875
)
[originX] => 36
[originY] => 0
)
All other characters look good. Only the lowercase 'g' seems to break queryFontMetrics for RNS.ttf.Array
(
[characterWidth] => 72
[characterHeight] => 72
[ascender] => 70
[descender] => -31
[textWidth] => 37.5625
[textHeight] => 103
[maxHorizontalAdvance] => 61
[boundingBox] => Array
(
[x1] => 0.4375
[y1] => -0.140625
[x2] => 35
[y2] => 54.078125
)
[originX] => 36
[originY] => 0
)
Another font example (GreatVibes-Regular.ttf), breaks for the letter 'u' in certain sizes:
https://github.com/google/fonts/tree/ma ... greatvibes
queryFontMetrics for the character 'u' in size 256:
Code: Select all
<?php
$image = new Imagick();
$fontDraw = new ImagickDraw();
$fontDraw->setFont('./GreatVibes-Regular.ttf');
$fontDraw->setFontSize(256);
$fontMetrics = $image->queryFontMetrics($fontDraw, 'g', FALSE);
print_r($fontMetrics);
?>
Debian 8 and Ubuntu 15.10 (bogus results):
Array
(
[characterWidth] => 72
[characterHeight] => 72
[ascender] => 70
[descender] => -31
[textWidth] => 33554469.1875
[textHeight] => 103
[maxHorizontalAdvance] => 61
[boundingBox] => Array
(
[x1] => -33554430.1875
[y1] => -0.09375
[x2] => 35
[y2] => 55.171875
)
[originX] => 36
[originY] => 0
)
Size 72 looks fine for the GreatVibes font.
Here is my stack:
$ apt-cache policy libfreetype6
Debian 7 (wheezy): 2.4.9-1.1+deb7u3
Debian 8 (jessie): 2.5.2-3+deb8u1
Ubuntu 15.10: 2.5.2-4ubuntu2
I have tried installing some different freetype versions by hand, but with the same results.
$ apt-cache policy imagemagick
Debian 7 (wheezy): 8:6.7.7.10-5+deb7u3
Debian 8 (jessie): 8:6.8.9.9-5
Ubuntu 15.10: 8:6.8.9.9-5ubuntu2
I also tried with manual install of ImageMagick-6.9.2-6 with same results.
$ apt-cache policy php5-imagick
Debian 7 (wheezy): 3.1.0~rc1-1+b2
Debian 8 (jessie): 3.2.0~rc1-1
Ubuntu 15.10: 3.3.0~rc2-1
I have tried several imagick versions via PECL with same results.
I have tried looking at two font files in the above examples, opening them in fontforge. I wasn't able to find any abnormalities with the disobedient characters, but then again my fontforge knowledge is very poor.