You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Charles Harris <Ch...@pkware.com.INVALID> on 2024/08/22 17:36:21 UTC
NullPointerException on bad Unicode font mapping
Hello, in pdfbox 3.0.0-alpha3 I am encountering the following error:
java.lang.NullPointerException: Cannot read the array length because "this.glyphIdToCharacterCode" is null
org.apache.fontbox.ttf.CmapSubtable.getCharCode(CmapSubtable.java:638)
org.apache.fontbox.ttf.CmapSubtable.getCharCodes(CmapSubtable.java:655)
org.apache.pdfbox.pdmodel.font.PDType0Font.toUnicode(PDType0Font.java:546)...
This is thrown by the following code :
while (currentPosition < bytes.size && currentCharacterBytes++ < maxEncodingBytes) {
potentialCode = potentialCode.shl(8).or(bytes[currentPosition++].toInt().and(0xFF))
val potentialRepresentation: String
potentialRepresentation = font.toUnicode(potentialCode) ?: continue // Exception is thrown here
unicodeRepresentation.append(potentialRepresentation)
codes.add(potentialCode)
currentCharacterBytes = 0
potentialCode = 0
}
Unfortunately, the pdf that caused this is not available, this error was discovered in review of the logs. Attempts to recreate the exception by creating a pdf through pdfbox and manually using different glyphs/fonts/emoji combinations were unsuccessful. From the exception itself, it would seem that the glyphIdToCharacterCode array in CmapSubtable is not being initialized.
Re: NullPointerException on bad Unicode font mapping
Posted by Tilman Hausherr <TH...@t-online.de>.
Answered last time:
https://lists.apache.org/thread/yltqzhbl8oltgxltg94wo5msdmwmwsrd
Tilman
On 22.08.2024 19:36, Charles Harris wrote:
> Hello, in pdfbox 3.0.0-alpha3 I am encountering the following error:
>
> java.lang.NullPointerException: Cannot read the array length because "this.glyphIdToCharacterCode" is null
> org.apache.fontbox.ttf.CmapSubtable.getCharCode(CmapSubtable.java:638)
> org.apache.fontbox.ttf.CmapSubtable.getCharCodes(CmapSubtable.java:655)
> org.apache.pdfbox.pdmodel.font.PDType0Font.toUnicode(PDType0Font.java:546)...
>
> This is thrown by the following code :
>
> while (currentPosition < bytes.size && currentCharacterBytes++ < maxEncodingBytes) {
> potentialCode = potentialCode.shl(8).or(bytes[currentPosition++].toInt().and(0xFF))
> val potentialRepresentation: String
> potentialRepresentation = font.toUnicode(potentialCode) ?: continue // Exception is thrown here
> unicodeRepresentation.append(potentialRepresentation)
> codes.add(potentialCode)
> currentCharacterBytes = 0
> potentialCode = 0
> }
>
> Unfortunately, the pdf that caused this is not available, this error was discovered in review of the logs. Attempts to recreate the exception by creating a pdf through pdfbox and manually using different glyphs/fonts/emoji combinations were unsuccessful. From the exception itself, it would seem that the glyphIdToCharacterCode array in CmapSubtable is not being initialized.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org