pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r1599019 - in /pdfbox/branches/1.8: ./ pdfbox/src/main/java/org/apache/pdfbox/encoding/SingleByteCharset.java pdfbox/src/test/java/org/apache/pdfbox/encoding/PDFDocEncodingCharsetTest.java
Date Sun, 01 Jun 2014 17:51:55 GMT
Author: jeremias
Date: Sun Jun  1 17:51:54 2014
New Revision: 1599019

URL: http://svn.apache.org/r1599019
Log:
PDFBOX-2102: Fix for IllegalArgumentException when the last character in the buffer is an
undefined character.

Modified:
    pdfbox/branches/1.8/   (props changed)
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/SingleByteCharset.java
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/encoding/PDFDocEncodingCharsetTest.java

Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
  Merged /pdfbox/trunk:r1599016

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/SingleByteCharset.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/SingleByteCharset.java?rev=1599019&r1=1599018&r2=1599019&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/SingleByteCharset.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/SingleByteCharset.java
Sun Jun  1 17:51:54 2014
@@ -137,6 +137,7 @@ public class SingleByteCharset extends C
                 ch = toUnicodeMap[b & 0xFF];
                 if (ch == REPLACEMENT_CHARACTER)
                 {
+                    in.position(in.position() - 1);
                     return CoderResult.unmappableForLength(1);
                 }
                 out.put(ch);

Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/encoding/PDFDocEncodingCharsetTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/encoding/PDFDocEncodingCharsetTest.java?rev=1599019&r1=1599018&r2=1599019&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/encoding/PDFDocEncodingCharsetTest.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/encoding/PDFDocEncodingCharsetTest.java
Sun Jun  1 17:51:54 2014
@@ -17,6 +17,9 @@
 package org.apache.pdfbox.encoding;
 
 import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
 
 import junit.framework.TestCase;
 
@@ -60,6 +63,23 @@ public class PDFDocEncodingCharsetTest e
         assertEquals("Bad??char", decoded);
     }
 
+    /**
+     * Checking for behaviour with undefined character at the end of the buffer.
+     * This used to cause an IllegalArgumentException.
+     */
+    public void testUnencodedAtEnd()
+    {
+        byte[] encoded = new byte[] {0x00, 0x01, 0x02, 0x7F}; //0x7F is undefined
+        String decoded = toString(encoded, 0, encoded.length, PDFDocEncodingCharset.INSTANCE);
+        assertEquals("\u0000\u0001\u0002\uFFFD", decoded);
+    }
+    
+    private static String toString(byte[] data, int offset, int length, Charset charset)
+    {
+        CharBuffer charBuffer = charset.decode(ByteBuffer.wrap(data, offset, length));
+        return charBuffer.toString();
+    }
+    
     private void compareEncoded(byte[] encoded, int[] expected)
     {
         assertEquals(expected.length, encoded.length);



Mime
View raw message