You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2016/04/27 13:53:05 UTC

tika git commit: TIKA-1924 upgrade isoparser to 1.1.18

Repository: tika
Updated Branches:
  refs/heads/2.x 403db9622 -> 7db4513c3


TIKA-1924 upgrade isoparser to 1.1.18


Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/7db4513c
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/7db4513c
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/7db4513c

Branch: refs/heads/2.x
Commit: 7db4513c3e3d050e9434a1997b0ccff6d8a8c3b0
Parents: 403db96
Author: tballison <ta...@mitre.org>
Authored: Wed Apr 27 07:52:57 2016 -0400
Committer: tballison <ta...@mitre.org>
Committed: Wed Apr 27 07:52:57 2016 -0400

----------------------------------------------------------------------
 CHANGES.txt                                     |   2 +
 .../tika-parser-multimedia-module/pom.xml       |   2 +-
 .../parser/mp4/DirectFileReadDataSource.java    |  34 +-
 .../org/apache/tika/parser/mp4/MP4Parser.java   | 355 ++++++++++---------
 .../apache/tika/parser/mp4/MP4ParserTest.java   |  13 +-
 .../test-documents/testMP4_truncated.m4a        | Bin 0 -> 74 bytes
 6 files changed, 223 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tika/blob/7db4513c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 05983ff..2308647 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -19,6 +19,8 @@ Release 1.13 - ???
     * Some truncated/corrupted files that had some content extracted
       with 1.8.x may have no content extracted in 2.0.x (see TIKA-1912).
 
+  * Upgrade MP4 isoparser to 1.1.18 (TIKA-1924).
+
   * Extract metadata from MP4 videos whether or not the
     PooledTimeSeries parser is available via Aditya Dhulipala
     (TIKA-1844).

http://git-wip-us.apache.org/repos/asf/tika/blob/7db4513c/tika-parser-modules/tika-parser-multimedia-module/pom.xml
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/pom.xml b/tika-parser-modules/tika-parser-multimedia-module/pom.xml
index 32b52cf..0192b8b 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/pom.xml
+++ b/tika-parser-modules/tika-parser-multimedia-module/pom.xml
@@ -25,7 +25,7 @@
   
   <properties>
     <metadata.extractor.version>2.8.1</metadata.extractor.version>
-    <isoparser.version>1.1.7</isoparser.version>
+    <isoparser.version>1.1.18</isoparser.version>
     <commons.logging.version>1.1.3</commons.logging.version>
   </properties>
   

http://git-wip-us.apache.org/repos/asf/tika/blob/7db4513c/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/DirectFileReadDataSource.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/DirectFileReadDataSource.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/DirectFileReadDataSource.java
index bea50a0..f25b413 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/DirectFileReadDataSource.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/DirectFileReadDataSource.java
@@ -16,15 +16,16 @@
  */
 package org.apache.tika.parser.mp4;
 
-import com.googlecode.mp4parser.DataSource;
+import static com.googlecode.mp4parser.util.CastUtils.l2i;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.nio.channels.WritableByteChannel;
 
-import static com.googlecode.mp4parser.util.CastUtils.l2i;
+import com.googlecode.mp4parser.DataSource;
 
 /**
  * A {@link DataSource} implementation that relies on direct reads from a {@link RandomAccessFile}.
@@ -59,10 +60,16 @@ public class DirectFileReadDataSource implements DataSource {
             }
             byteBuffer.put(buf, 0, bytesRead);
         }
+        if (bytesRead < 0 && position() == size() && byteBuffer.hasRemaining()) {
+            throw new IOException("End of stream reached earlier than expected");
+        }
         return ((bytesRead < 0) && (totalRead == 0)) ? -1 : totalRead;
     }
 
     public int readAllInOnce(ByteBuffer byteBuffer) throws IOException {
+        if (byteBuffer.remaining() > raf.length()) {
+            throw new IOException("trying to readAllInOnce past end of stream");
+        }
         byte[] buf = new byte[byteBuffer.remaining()];
         int read = raf.read(buf);
         byteBuffer.put(buf, 0, read);
@@ -78,6 +85,9 @@ public class DirectFileReadDataSource implements DataSource {
     }
 
     public void position(long nuPos) throws IOException {
+        if (nuPos > raf.length()) {
+            throw new IOException("requesting seek past end of stream");
+        }
         raf.seek(nuPos);
     }
 
@@ -86,12 +96,30 @@ public class DirectFileReadDataSource implements DataSource {
     }
 
     public ByteBuffer map(long startPosition, long size) throws IOException {
+        if (startPosition < 0 || size < 0) {
+            throw new IOException("startPosition and size must both be >= 0");
+        }
+        //make sure that start+size aren't greater than avail size
+        //in raf.
+        BigInteger end = BigInteger.valueOf(startPosition);
+        end.add(BigInteger.valueOf(size));
+        if (end.compareTo(BigInteger.valueOf(raf.length())) > 0) {
+            throw new IOException("requesting read past end of stream");
+        }
+
         raf.seek(startPosition);
-        byte[] payload = new byte[l2i(size)];
+        int payLoadSize = l2i(size);
+        //hack to check for potential overflow
+        if (Long.MAX_VALUE-payLoadSize < startPosition ||
+                Long.MAX_VALUE-payLoadSize > raf.length()) {
+            throw new IOException("requesting read past end of stream");
+        }
+        byte[] payload = new byte[payLoadSize];
         raf.readFully(payload);
         return ByteBuffer.wrap(payload);
     }
 
+    @Override
     public void close() throws IOException {
         raf.close();
     }

http://git-wip-us.apache.org/repos/asf/tika/blob/7db4513c/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
index 20c8246..5a2d74d 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
@@ -28,6 +28,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
+import com.googlecode.mp4parser.DataSource;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.io.TemporaryResources;
 import org.apache.tika.io.TikaInputStream;
@@ -74,7 +75,7 @@ import com.googlecode.mp4parser.boxes.apple.Utf8AppleDataBox;
 /**
  * Parser for the MP4 media container format, as well as the older
  *  QuickTime format that MP4 is based on.
- * 
+ *
  * This uses the MP4Parser project from http://code.google.com/p/mp4parser/
  *  to do the underlying parsing
  */
@@ -82,12 +83,12 @@ public class MP4Parser extends AbstractParser {
     /** Serial version UID */
     private static final long serialVersionUID = 84011216792285L;
     /** TODO Replace this with a 2dp Duration Property Converter */
-    private static final DecimalFormat DURATION_FORMAT = 
-            (DecimalFormat)NumberFormat.getNumberInstance(Locale.ROOT); 
+    private static final DecimalFormat DURATION_FORMAT =
+            (DecimalFormat)NumberFormat.getNumberInstance(Locale.ROOT);
     static {
         DURATION_FORMAT.applyPattern("0.0#");
     }
-    
+
     // Ensure this stays in Sync with the entries in tika-mimetypes.xml
     private static final Map<MediaType,List<String>> typesMap = new HashMap<MediaType, List<String>>();
     static {
@@ -102,7 +103,7 @@ public class MP4Parser extends AbstractParser {
              "mp41", "mp42"));
        typesMap.put(MediaType.video("x-m4v"), Arrays.asList(
              "M4V ", "M4VH", "M4VP"));
-       
+
        typesMap.put(MediaType.video("quicktime"), Collections.<String>emptyList());
        typesMap.put(MediaType.application("mp4"), Collections.<String>emptyList());
     }
@@ -119,189 +120,189 @@ public class MP4Parser extends AbstractParser {
             InputStream stream, ContentHandler handler,
             Metadata metadata, ParseContext context)
             throws IOException, SAXException, TikaException {
-        IsoFile isoFile;
-        
+
         // The MP4Parser library accepts either a File, or a byte array
         // As MP4 video files are typically large, always use a file to
         //  avoid OOMs that may occur with in-memory buffering
         TemporaryResources tmp = new TemporaryResources();
         TikaInputStream tstream = TikaInputStream.get(stream, tmp);
-        try {
-            isoFile = new IsoFile(new DirectFileReadDataSource(tstream.getFile()));
-            tmp.addResource(isoFile);
-
-            // Grab the file type box
-            FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class);
-            if (fileType != null) {
-               // Identify the type
-               MediaType type = MediaType.application("mp4");
-               for (MediaType t : typesMap.keySet()) {
-                  if (typesMap.get(t).contains(fileType.getMajorBrand())) {
-                     type = t;
-                     break;
-                  }
-               }
-               metadata.set(Metadata.CONTENT_TYPE, type.toString());
-
-               if (type.getType().equals("audio")) {
-                  metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim());
-               }
-            } else {
-               // Some older QuickTime files lack the FileType
-               metadata.set(Metadata.CONTENT_TYPE, "video/quicktime");
-            }
-
-
-            // Get the main MOOV box
-            MovieBox moov = getOrNull(isoFile, MovieBox.class);
-            if (moov == null) {
-               // Bail out
-               return;
-            }
-
-
-            XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
-            xhtml.startDocument();
-
 
-            // Pull out some information from the header box
-            MovieHeaderBox mHeader = getOrNull(moov, MovieHeaderBox.class);
-            if (mHeader != null) {
-               // Get the creation and modification dates
-               metadata.set(Metadata.CREATION_DATE, mHeader.getCreationTime());
-               metadata.set(TikaCoreProperties.MODIFIED, mHeader.getModificationTime());
-
-               // Get the duration
-               double durationSeconds = ((double)mHeader.getDuration()) / mHeader.getTimescale();
-               metadata.set(XMPDM.DURATION, DURATION_FORMAT.format(durationSeconds));
-
-               // The timescale is normally the sampling rate
-               metadata.set(XMPDM.AUDIO_SAMPLE_RATE, (int)mHeader.getTimescale());
-            }
-
-
-            // Get some more information from the track header
-            // TODO Decide how to handle multiple tracks
-            List<TrackBox> tb = moov.getBoxes(TrackBox.class);
-            if (tb.size() > 0) {
-               TrackBox track = tb.get(0);
-
-               TrackHeaderBox header = track.getTrackHeaderBox();
-               // Get the creation and modification dates
-               metadata.set(TikaCoreProperties.CREATED, header.getCreationTime());
-               metadata.set(TikaCoreProperties.MODIFIED, header.getModificationTime());
-
-               // Get the video with and height
-               metadata.set(Metadata.IMAGE_WIDTH,  (int)header.getWidth());
-               metadata.set(Metadata.IMAGE_LENGTH, (int)header.getHeight());
-
-               // Get the sample information
-               SampleTableBox samples = track.getSampleTableBox();
-               SampleDescriptionBox sampleDesc = samples.getSampleDescriptionBox();
-               if (sampleDesc != null) {
-                  // Look for the first Audio Sample, if present
-                  AudioSampleEntry sample = getOrNull(sampleDesc, AudioSampleEntry.class);
-                  if (sample != null) {
-                     XMPDM.ChannelTypePropertyConverter.convertAndSet(metadata, sample.getChannelCount());
-                     //metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, sample.getSampleSize());    // TODO Num -> Type mapping
-                     metadata.set(XMPDM.AUDIO_SAMPLE_RATE, (int)sample.getSampleRate());
-                     //metadata.set(XMPDM.AUDIO_, sample.getSamplesPerPacket());
-                     //metadata.set(XMPDM.AUDIO_, sample.getBytesPerSample());
-                  }
-               }
+        try (DataSource dataSource = new DirectFileReadDataSource(tstream.getFile())) {
+            try (IsoFile isoFile = new IsoFile(dataSource)) {
+                tmp.addResource(isoFile);
+
+                // Grab the file type box
+                FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class);
+                if (fileType != null) {
+                    // Identify the type
+                    MediaType type = MediaType.application("mp4");
+                    for (MediaType t : typesMap.keySet()) {
+                        if (typesMap.get(t).contains(fileType.getMajorBrand())) {
+                            type = t;
+                            break;
+                        }
+                    }
+                    metadata.set(Metadata.CONTENT_TYPE, type.toString());
+
+                    if (type.getType().equals("audio")) {
+                        metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim());
+                    }
+                } else {
+                    // Some older QuickTime files lack the FileType
+                    metadata.set(Metadata.CONTENT_TYPE, "video/quicktime");
+                }
+
+
+                // Get the main MOOV box
+                MovieBox moov = getOrNull(isoFile, MovieBox.class);
+                if (moov == null) {
+                    // Bail out
+                    return;
+                }
+
+
+                XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
+                xhtml.startDocument();
+
+
+                // Pull out some information from the header box
+                MovieHeaderBox mHeader = getOrNull(moov, MovieHeaderBox.class);
+                if (mHeader != null) {
+                    // Get the creation and modification dates
+                    metadata.set(Metadata.CREATION_DATE, mHeader.getCreationTime());
+                    metadata.set(TikaCoreProperties.MODIFIED, mHeader.getModificationTime());
+
+                    // Get the duration
+                    double durationSeconds = ((double) mHeader.getDuration()) / mHeader.getTimescale();
+                    metadata.set(XMPDM.DURATION, DURATION_FORMAT.format(durationSeconds));
+
+                    // The timescale is normally the sampling rate
+                    metadata.set(XMPDM.AUDIO_SAMPLE_RATE, (int) mHeader.getTimescale());
+                }
+
+
+                // Get some more information from the track header
+                // TODO Decide how to handle multiple tracks
+                List<TrackBox> tb = moov.getBoxes(TrackBox.class);
+                if (tb.size() > 0) {
+                    TrackBox track = tb.get(0);
+
+                    TrackHeaderBox header = track.getTrackHeaderBox();
+                    // Get the creation and modification dates
+                    metadata.set(TikaCoreProperties.CREATED, header.getCreationTime());
+                    metadata.set(TikaCoreProperties.MODIFIED, header.getModificationTime());
+
+                    // Get the video with and height
+                    metadata.set(Metadata.IMAGE_WIDTH, (int) header.getWidth());
+                    metadata.set(Metadata.IMAGE_LENGTH, (int) header.getHeight());
+
+                    // Get the sample information
+                    SampleTableBox samples = track.getSampleTableBox();
+                    SampleDescriptionBox sampleDesc = samples.getSampleDescriptionBox();
+                    if (sampleDesc != null) {
+                        // Look for the first Audio Sample, if present
+                        AudioSampleEntry sample = getOrNull(sampleDesc, AudioSampleEntry.class);
+                        if (sample != null) {
+                            XMPDM.ChannelTypePropertyConverter.convertAndSet(metadata, sample.getChannelCount());
+                            //metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, sample.getSampleSize());    // TODO Num -> Type mapping
+                            metadata.set(XMPDM.AUDIO_SAMPLE_RATE, (int) sample.getSampleRate());
+                            //metadata.set(XMPDM.AUDIO_, sample.getSamplesPerPacket());
+                            //metadata.set(XMPDM.AUDIO_, sample.getBytesPerSample());
+                        }
+                    }
+                }
+
+                // Get metadata from the User Data Box
+                UserDataBox userData = getOrNull(moov, UserDataBox.class);
+                if (userData != null) {
+                    MetaBox meta = getOrNull(userData, MetaBox.class);
+
+                    // Check for iTunes Metadata
+                    // See http://atomicparsley.sourceforge.net/mpeg-4files.html and
+                    //  http://code.google.com/p/mp4v2/wiki/iTunesMetadata for more on these
+                    AppleItemListBox apple = getOrNull(meta, AppleItemListBox.class);
+                    if (apple != null) {
+                        // Title
+                        AppleNameBox title = getOrNull(apple, AppleNameBox.class);
+                        addMetadata(TikaCoreProperties.TITLE, metadata, title);
+
+                        // Artist
+                        AppleArtistBox artist = getOrNull(apple, AppleArtistBox.class);
+                        addMetadata(TikaCoreProperties.CREATOR, metadata, artist);
+                        addMetadata(XMPDM.ARTIST, metadata, artist);
+
+                        // Album Artist
+                        AppleArtist2Box artist2 = getOrNull(apple, AppleArtist2Box.class);
+                        addMetadata(XMPDM.ALBUM_ARTIST, metadata, artist2);
+
+                        // Album
+                        AppleAlbumBox album = getOrNull(apple, AppleAlbumBox.class);
+                        addMetadata(XMPDM.ALBUM, metadata, album);
+
+                        // Composer
+                        AppleTrackAuthorBox composer = getOrNull(apple, AppleTrackAuthorBox.class);
+                        addMetadata(XMPDM.COMPOSER, metadata, composer);
+
+                        // Genre
+                        AppleGenreBox genre = getOrNull(apple, AppleGenreBox.class);
+                        addMetadata(XMPDM.GENRE, metadata, genre);
+
+                        // Year
+                        AppleRecordingYear2Box year = getOrNull(apple, AppleRecordingYear2Box.class);
+                        if (year != null) {
+                            metadata.set(XMPDM.RELEASE_DATE, year.getValue());
+                        }
+
+                        // Track number
+                        AppleTrackNumberBox trackNum = getOrNull(apple, AppleTrackNumberBox.class);
+                        if (trackNum != null) {
+                            metadata.set(XMPDM.TRACK_NUMBER, trackNum.getA());
+                            //metadata.set(XMPDM.NUMBER_OF_TRACKS, trackNum.getB()); // TODO
+                        }
+
+                        // Disc number
+                        AppleDiskNumberBox discNum = getOrNull(apple, AppleDiskNumberBox.class);
+                        if (discNum != null) {
+                            metadata.set(XMPDM.DISC_NUMBER, discNum.getA());
+                        }
+
+                        // Compilation
+                        AppleCompilationBox compilation = getOrNull(apple, AppleCompilationBox.class);
+                        if (compilation != null) {
+                            metadata.set(XMPDM.COMPILATION, (int) compilation.getValue());
+                        }
+
+                        // Comment
+                        AppleCommentBox comment = getOrNull(apple, AppleCommentBox.class);
+                        addMetadata(XMPDM.LOG_COMMENT, metadata, comment);
+
+                        // Encoder
+                        AppleEncoderBox encoder = getOrNull(apple, AppleEncoderBox.class);
+                        if (encoder != null) {
+                            metadata.set(XMP.CREATOR_TOOL, encoder.getValue());
+                        }
+
+
+                        // As text
+                        for (Box box : apple.getBoxes()) {
+                            if (box instanceof Utf8AppleDataBox) {
+                                xhtml.element("p", ((Utf8AppleDataBox) box).getValue());
+                            }
+                        }
+                    }
+
+                    // TODO Check for other kinds too
+                }
+
+                // All done
+                xhtml.endDocument();
             }
-
-            // Get metadata from the User Data Box
-            UserDataBox userData = getOrNull(moov, UserDataBox.class);
-            if (userData != null) {
-               MetaBox meta = getOrNull(userData, MetaBox.class);
-
-               // Check for iTunes Metadata
-               // See http://atomicparsley.sourceforge.net/mpeg-4files.html and
-               //  http://code.google.com/p/mp4v2/wiki/iTunesMetadata for more on these
-               AppleItemListBox apple = getOrNull(meta, AppleItemListBox.class);
-               if (apple != null) {
-                  // Title
-                  AppleNameBox title = getOrNull(apple, AppleNameBox.class);
-                  addMetadata(TikaCoreProperties.TITLE, metadata, title);
-
-                  // Artist
-                  AppleArtistBox artist = getOrNull(apple, AppleArtistBox.class);
-                  addMetadata(TikaCoreProperties.CREATOR, metadata, artist);
-                  addMetadata(XMPDM.ARTIST, metadata, artist);
-
-                  // Album Artist
-                  AppleArtist2Box artist2 = getOrNull(apple, AppleArtist2Box.class);
-                  addMetadata(XMPDM.ALBUM_ARTIST, metadata, artist2);
-
-                  // Album
-                  AppleAlbumBox album = getOrNull(apple, AppleAlbumBox.class);
-                  addMetadata(XMPDM.ALBUM, metadata, album);
-
-                  // Composer
-                  AppleTrackAuthorBox composer = getOrNull(apple, AppleTrackAuthorBox.class);
-                  addMetadata(XMPDM.COMPOSER, metadata, composer);
-
-                  // Genre
-                  AppleGenreBox genre = getOrNull(apple, AppleGenreBox.class);
-                  addMetadata(XMPDM.GENRE, metadata, genre);
-
-                  // Year
-                  AppleRecordingYear2Box year = getOrNull(apple, AppleRecordingYear2Box.class);
-                  if (year != null) {
-                      metadata.set(XMPDM.RELEASE_DATE, year.getValue());
-                  }
-
-                  // Track number
-                  AppleTrackNumberBox trackNum = getOrNull(apple, AppleTrackNumberBox.class);
-                  if (trackNum != null) {
-                     metadata.set(XMPDM.TRACK_NUMBER, trackNum.getA());
-                     //metadata.set(XMPDM.NUMBER_OF_TRACKS, trackNum.getB()); // TODO
-                  }
-
-                  // Disc number
-                  AppleDiskNumberBox discNum = getOrNull(apple, AppleDiskNumberBox.class);
-                  if (discNum != null) {
-                     metadata.set(XMPDM.DISC_NUMBER, discNum.getA());
-                  }
-
-                  // Compilation
-                  AppleCompilationBox compilation = getOrNull(apple, AppleCompilationBox.class);
-                  if (compilation != null) {
-                      metadata.set(XMPDM.COMPILATION, (int)compilation.getValue());
-                  }
-
-                  // Comment
-                  AppleCommentBox comment = getOrNull(apple, AppleCommentBox.class);
-                  addMetadata(XMPDM.LOG_COMMENT, metadata, comment);
-
-                  // Encoder
-                  AppleEncoderBox encoder = getOrNull(apple, AppleEncoderBox.class);
-                  if (encoder != null) {
-                      metadata.set(XMP.CREATOR_TOOL, encoder.getValue());
-                  }
-
-
-                  // As text
-                  for (Box box : apple.getBoxes()) {
-                     if (box instanceof Utf8AppleDataBox) {
-                        xhtml.element("p", ((Utf8AppleDataBox)box).getValue());
-                     }
-                  }
-               }
-
-               // TODO Check for other kinds too
-            }
-
-            // All done
-            xhtml.endDocument();
-
         } finally {
             tmp.dispose();
         }
 
     }
-    
+
     private static void addMetadata(String key, Metadata m, Utf8AppleDataBox metadata) {
        if (metadata != null) {
           m.add(key, metadata.getValue());
@@ -312,7 +313,7 @@ public class MP4Parser extends AbstractParser {
           m.set(prop, metadata.getValue());
        }
     }
-    
+
     private static <T extends Box> T getOrNull(Container box, Class<T> clazz) {
        if (box == null) return null;
 

http://git-wip-us.apache.org/repos/asf/tika/blob/7db4513c/tika-parser-modules/tika-parser-multimedia-module/src/test/java/org/apache/tika/parser/mp4/MP4ParserTest.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/test/java/org/apache/tika/parser/mp4/MP4ParserTest.java b/tika-parser-modules/tika-parser-multimedia-module/src/test/java/org/apache/tika/parser/mp4/MP4ParserTest.java
index d4dc394..fc7f913 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/test/java/org/apache/tika/parser/mp4/MP4ParserTest.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/test/java/org/apache/tika/parser/mp4/MP4ParserTest.java
@@ -16,11 +16,11 @@
  */
 package org.apache.tika.parser.mp4;
 
-import static org.apache.tika.TikaTest.assertContains;
 import static org.junit.Assert.assertEquals;
 
 import java.io.InputStream;
 
+import org.apache.tika.TikaTest;
 import org.apache.tika.io.TikaInputStream;
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.metadata.TikaCoreProperties;
@@ -36,7 +36,7 @@ import org.xml.sax.ContentHandler;
 /**
  * Test case for parsing mp4 files.
  */
-public class MP4ParserTest {
+public class MP4ParserTest extends TikaTest {
     /**
      * Test that we can extract information from
      *  a M4A MP4 Audio file
@@ -105,4 +105,13 @@ public class MP4ParserTest {
     
     // TODO Test a MP4 Video file
     // TODO Test an old QuickTime Video File
+
+    @Test(timeout = 30000)
+    public void testInfiniteLoop() throws Exception {
+        //test that a truncated mp4 doesn't cause an infinite loop
+        //TIKA-1931 and TIKA-1924
+        XMLResult r = getXML("testMP4_truncated.m4a");
+        assertEquals("audio/mp4", r.metadata.get(Metadata.CONTENT_TYPE));
+        assertEquals("M4A", r.metadata.get(XMPDM.AUDIO_COMPRESSOR));
+    }
 }

http://git-wip-us.apache.org/repos/asf/tika/blob/7db4513c/tika-test-resources/src/test/resources/test-documents/testMP4_truncated.m4a
----------------------------------------------------------------------
diff --git a/tika-test-resources/src/test/resources/test-documents/testMP4_truncated.m4a b/tika-test-resources/src/test/resources/test-documents/testMP4_truncated.m4a
new file mode 100644
index 0000000..31fdef4
Binary files /dev/null and b/tika-test-resources/src/test/resources/test-documents/testMP4_truncated.m4a differ