[OpenJDK 2D-Dev] [9] RFR JDK-7160052: GlyphVector.setGlyphPosition can throw an exception on valid input

prasanta sadhukhan prasanta.sadhukhan at oracle.com
Fri Nov 27 11:48:21 UTC 2015


Hi All,

Please review a fix for jdk9
Bug: https://bugs.openjdk.java.net/browse/JDK-7160052
webrev: http://cr.openjdk.java.net/~psadhukhan/7160052/webrev.00/

Issue:
GlyphVector.setGlyphPosition(int glyphIndex, Point2D 
<cid:part1.01090803.05010309 at oracle.com> newPos) can have glyphIndex 
"equal" to the number of glyphs in this GlyphVector
so if user tries to call GlyphVector.setGlyphPosition(gv.getNumGlyphs(), 
gv.getGlyphPosition(gv.getNumGlyphs()) it throws IndexOutOfBoundsException

Cause:
StandardGlyphVector maintains a glyph cache for the glyphs stored in the 
GlyphVector via lbcache = new Shape[glyphs.length];

When GlyphVector.setGlyphPosition() is called, it positions the glyph at 
the specified glyphIndex|||||||||| and tries to clear the mentioned 
glyphIndex position of cache by calling clearCache(glyphIndex)
But, if we pass the glyphIndex == number of glyphs, then it tries to 
access beyond the cache array resulting in IOB.

Fix:
Checked if glyphIndex passed as argument is equal to number of glyphs 
then do not try to clear the cache as setGlyphPosition() will anyway 
sets the position after the last glyph.
Also, added this check as per spec|IndexOutOfBoundsException 
<cid:part2.03060502.08060102 at oracle.com>| - if |glyphIndex| is less than 
0 or greater than the number of glyphs in this |GlyphVector
|
Regards
Prasanta

||||
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20151127/193b0bba/attachment.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20151127/193b0bba/Point2D.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20151127/193b0bba/IndexOutOfBoundsException.html>


More information about the 2d-dev mailing list