Author: kiwiwings
Date: Fri Apr 24 21:31:49 2020
New Revision: 1876951

URL: http://svn.apache.org/viewvc?rev=1876951&view=rev
Log:
Replace assertion with exception

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java
    
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java?rev=1876951&r1=1876950&r2=1876951&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java 
Fri Apr 24 21:31:49 2020
@@ -461,17 +461,17 @@ public class HemfFont extends HwmfFont {
             // A 32-bit unsigned integer that specifies the number of elements 
in the
             // Values array. It MUST be in the range 0 to 16, inclusive.
             int numAxes = leis.readInt();
-            assert (0 <= numAxes && numAxes <= 16);
+            size += 2*LittleEndianConsts.INT_SIZE;
 
             // An optional array of 32-bit signed integers that specify the 
values of the font axes of a
             // multiple master, OpenType font. The maximum number of values in 
the array is 16.
-            if (numAxes > 0) {
+            if (0 <= numAxes && numAxes <= 16) {
                 logEx.designVector = new int[numAxes];
                 for (int i=0; i<numAxes; i++) {
                     logEx.designVector[i] = leis.readInt();
                 }
+                size += numAxes*LittleEndianConsts.INT_SIZE;
             }
-            size += (2+numAxes)*LittleEndianConsts.INT_SIZE;
         }
 
         return size;
@@ -532,9 +532,9 @@ public class HemfFont extends HwmfFont {
             b1 = buf[readBytes++];
             b2 = buf[readBytes++];
         } while ((b1 != 0 || b2 != 0) && b1 != -1 && b2 != -1 && readBytes <= 
limit*2);
-
         sb.append(new String(buf, 0, readBytes-2, StandardCharsets.UTF_16LE));
 
         return limit*2;
     }
 }
+

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java?rev=1876951&r1=1876950&r2=1876951&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java
 Fri Apr 24 21:31:49 2020
@@ -78,7 +78,9 @@ public class HemfRecordIterator implemen
         try {
             long remBytes = recordSize - HEADER_SIZE;
             long readBytes = record.init(stream, remBytes, recordId);
-            assert (readBytes <= remBytes);
+            if (readBytes > remBytes) {
+                throw new RecordFormatException("Record limit exceeded - 
readBytes: "+readBytes+" / remBytes: "+remBytes);
+            }
             stream.skipFully((int) (remBytes - readBytes));
         } catch (RecordFormatException e) {
             throw e;



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to