diff --git a/src/share/classes/sun/font/CMap.java b/src/share/classes/sun/font/CMap.java index 73cfcc7d07facf8841aa3ecb546e086290692efb..1565a652a541782b8f5795660ad52fa5efee17bb 100644 --- a/src/share/classes/sun/font/CMap.java +++ b/src/share/classes/sun/font/CMap.java @@ -130,7 +130,7 @@ abstract class CMap { static final char noSuchChar = (char)0xfffd; static final int SHORTMASK = 0x0000ffff; - static final int INTMASK = 0xffffffff; + static final int INTMASK = 0x7fffffff; static final char[][] converterMaps = new char[7][]; @@ -885,7 +885,11 @@ abstract class CMap { bbuffer.position(12); bbuffer.get(is32); - nGroups = bbuffer.getInt(); + nGroups = bbuffer.getInt() & INTMASK; + // A map group record is three uint32's making for 12 bytes total + if (bbuffer.remaining() < (12 * (long)nGroups)) { + throw new RuntimeException("Format 8 table exceeded"); + } startCharCode = new int[nGroups]; endCharCode = new int[nGroups]; startGlyphID = new int[nGroups]; @@ -913,9 +917,13 @@ abstract class CMap { CMapFormat10(ByteBuffer bbuffer, int offset, char[] xlat) { + bbuffer.position(offset+12); firstCode = bbuffer.getInt() & INTMASK; entryCount = bbuffer.getInt() & INTMASK; - bbuffer.position(offset+20); + // each glyph is a uint16, so 2 bytes per value. + if (bbuffer.remaining() < (2 * (long)entryCount)) { + throw new RuntimeException("Format 10 table exceeded"); + } CharBuffer buffer = bbuffer.asCharBuffer(); glyphIdArray = new char[entryCount]; for (int i=0; i< entryCount; i++) { @@ -955,11 +963,15 @@ abstract class CMap { throw new RuntimeException("xlat array for cmap fmt=12"); } - numGroups = buffer.getInt(offset+12); + buffer.position(offset+12); + numGroups = buffer.getInt() & INTMASK; + // A map group record is three uint32's making for 12 bytes total + if (buffer.remaining() < (12 * (long)numGroups)) { + throw new RuntimeException("Format 12 table exceeded"); + } startCharCode = new long[numGroups]; endCharCode = new long[numGroups]; startGlyphID = new int[numGroups]; - buffer.position(offset+16); buffer = buffer.slice(); IntBuffer ibuffer = buffer.asIntBuffer(); for (int i=0; i