Skip to content

Commit 95bf2c0

Browse files
committed
8237782: Only read advances up to the minimum of the numHorMetrics or the available font data.
Reviewed-by: kcr
1 parent d05e8fc commit 95bf2c0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

modules/javafx.graphics/src/main/java/com/sun/javafx/font/PrismFontFile.java

+18
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,15 @@ public void setPeer(Object peer) {
403403
this.peer = peer;
404404
}
405405

406+
int getTableLength(int tag) {
407+
int len = 0;
408+
DirectoryEntry tagDE = getDirectoryEntry(tag);
409+
if (tagDE != null) {
410+
len = tagDE.length;
411+
}
412+
return len;
413+
}
414+
406415
synchronized Buffer readTable(int tag) {
407416
Buffer buffer = null;
408417
boolean openedFile = false;
@@ -569,6 +578,15 @@ private void init(String name, int fIndex) throws Exception {
569578
// font. For some fonts advanceWidthMax is much larger then "M"
570579
// advanceWidthMax = (float)hhea.getChar(10);
571580
numHMetrics = hhea.getChar(34) & 0xffff;
581+
/* the hmtx table may have a trailing LSB array which we don't
582+
* use. But it means we must not assume these two values match.
583+
* We are only concerned here with not reading more data than
584+
* there is in the table.
585+
*/
586+
int hmtxEntries = getTableLength(hmtxTag) >> 2;
587+
if (numHMetrics > hmtxEntries) {
588+
numHMetrics = hmtxEntries;
589+
}
572590
}
573591

574592
// maxp table is before the OS/2 table. Read it now

0 commit comments

Comments
 (0)