[libbluray-devel] [PATCH] Fix parsing of dvd.fontidex files specifying an unresolvable dtd file

Andreas Zelend ace at kodi.tv
Thu Nov 6 23:44:30 CET 2014


This fixes/prevents an exception while parsing dvb.fontidex files with an
unresolvable dtd file.
For example:

<?xml version="1.0"?>
<!DOCTYPE fontdirectory PUBLIC "-//DVB//DTD Font Directory 1.0//EN" "
http://www.dvb.org/mhp/dtd/fontdirectory-1-0.dtd">
<fontdirectory>
    <font>
        <name>Miramonte</name>
        <fontformat>OTF</fontformat>
        <filename>00000.otf</filename>
        <style>BOLD</style>
    </font>
    <font>
        <name>MS Gothic</name>
        <fontformat>OTF</fontformat>
        <filename>00001.otf</filename>
        <style>PLAIN</style>
    </font>
</fontdirectory>


Reference:
https://stackoverflow.com/questions/1185519/how-to-read-well-formed-xml-in-java-but-skip-the-schema

I'm not sure if a "blacklist" approach is good, so comments welcome...


>From a248a991aebfed760ab06ebddf9e2ed5d6501819 Mon Sep 17 00:00:00 2001
From: ace20022 <ace20022 at ymail.com>
Date: Thu, 6 Nov 2014 23:17:56 +0100
Subject: [PATCH 1/1] FontIndex: Fix parsing dvb.fontidex files with
 unreachable dtd file definition.

---
 src/libbluray/bdj/java/org/videolan/FontIndex.java | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/libbluray/bdj/java/org/videolan/FontIndex.java
b/src/libbluray/bdj/java/org/videolan/FontIndex.java
index 9eb856f..fcdca35 100644
--- a/src/libbluray/bdj/java/org/videolan/FontIndex.java
+++ b/src/libbluray/bdj/java/org/videolan/FontIndex.java
@@ -22,15 +22,19 @@ package org.videolan;
 import java.awt.Font;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.StringReader;
 import java.util.ArrayList;

 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;

-public class FontIndex extends DefaultHandler {
+public class FontIndex extends DefaultHandler implements EntityResolver{
     public static FontIndexData[] parseIndex(String path) {
         return new FontIndex(path).getFontIndexData();
     }
@@ -60,6 +64,15 @@ public class FontIndex extends DefaultHandler {
         return (FontIndexData[])fontDatas.toArray(new
FontIndexData[fontDatas.size()]);
     }

+    public InputSource resolveEntity(String publicId, String systemId)
+            throws SAXException, IOException {
+        if (systemId.contains("
http://www.dvb.org/mhp/dtd/fontdirectory-1-0.dtd")) {
+            return new InputSource(new StringReader(""));
+        } else {
+            return null;
+        }
+    }
+
     public void startElement (String uri, String localName, String qName,
Attributes attributes)
         throws SAXException {
         if (qName.equalsIgnoreCase("fontdirectory")) {
-- 
1.9.2.msysgit.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/libbluray-devel/attachments/20141106/19b7324b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-FontIndex-Fix-parsing-dvd.fontidex-files-with-unreac.patch
Type: application/octet-stream
Size: 2075 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/libbluray-devel/attachments/20141106/19b7324b/attachment-0001.obj>


More information about the libbluray-devel mailing list