diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-01-27 09:03:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 09:03:31 +0100 |
commit | 0e0c4dda69f1085c712c3812ad61b1f05d05a43a (patch) | |
tree | bf2b2366713fd0077830d52878b46a305844ebc9 | |
parent | 2524fa0f7605ded2139f3ec6d4337383e6f3006d (diff) | |
parent | f8927ebc67190a80e969a8ff3fb11f74d2c74688 (diff) | |
download | antennapod-0e0c4dda69f1085c712c3812ad61b1f05d05a43a.zip |
Merge pull request #5675 from ByteHamster/do-not-hang-vorbis
Do not hang trying to parse ogg/vorbis chapters
-rw-r--r-- | parser/media/src/main/java/de/danoeh/antennapod/parser/media/vorbis/VorbisCommentReader.java | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/vorbis/VorbisCommentReader.java b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/vorbis/VorbisCommentReader.java index 607172531..3d5f29f17 100644 --- a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/vorbis/VorbisCommentReader.java +++ b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/vorbis/VorbisCommentReader.java @@ -41,7 +41,7 @@ public abstract class VorbisCommentReader { public void readInputStream(InputStream input) throws VorbisCommentReaderException { try { - skipIdentificationHeader(input); + findIdentificationHeader(input); onVorbisCommentFound(); findOggPage(input); findCommentHeader(input); @@ -61,7 +61,11 @@ public abstract class VorbisCommentReader { byte[] buffer = new byte[4]; final byte[] oggPageHeader = {'O', 'g', 'g', 'S'}; for (int bytesRead = 0; bytesRead < SECOND_PAGE_MAX_LENGTH; bytesRead++) { - buffer[bytesRead % buffer.length] = (byte) input.read(); + int data = input.read(); + if (data == -1) { + throw new IOException("EOF while trying to find vorbis page"); + } + buffer[bytesRead % buffer.length] = (byte) data; if (bufferMatches(buffer, oggPageHeader, bytesRead)) { break; } @@ -103,7 +107,7 @@ public abstract class VorbisCommentReader { * Looks for an identification header in the first page of the file. If an * identification header is found, it will be skipped completely */ - private void skipIdentificationHeader(InputStream input) throws IOException { + private void findIdentificationHeader(InputStream input) throws IOException { byte[] buffer = new byte[FIRST_OPUS_PAGE_LENGTH]; IOUtils.readFully(input, buffer); final byte[] oggIdentificationHeader = new byte[]{ PACKET_TYPE_IDENTIFICATION, 'v', 'o', 'r', 'b', 'i', 's' }; @@ -115,6 +119,7 @@ public abstract class VorbisCommentReader { return; } } + throw new IOException("No vorbis identification header found"); } private void findCommentHeader(InputStream input) throws IOException { |