Do not hang trying to parse ogg/vorbis chapters
This commit is contained in:
parent
2524fa0f76
commit
f8927ebc67
|
@ -41,7 +41,7 @@ public abstract class VorbisCommentReader {
|
||||||
|
|
||||||
public void readInputStream(InputStream input) throws VorbisCommentReaderException {
|
public void readInputStream(InputStream input) throws VorbisCommentReaderException {
|
||||||
try {
|
try {
|
||||||
skipIdentificationHeader(input);
|
findIdentificationHeader(input);
|
||||||
onVorbisCommentFound();
|
onVorbisCommentFound();
|
||||||
findOggPage(input);
|
findOggPage(input);
|
||||||
findCommentHeader(input);
|
findCommentHeader(input);
|
||||||
|
@ -61,7 +61,11 @@ public abstract class VorbisCommentReader {
|
||||||
byte[] buffer = new byte[4];
|
byte[] buffer = new byte[4];
|
||||||
final byte[] oggPageHeader = {'O', 'g', 'g', 'S'};
|
final byte[] oggPageHeader = {'O', 'g', 'g', 'S'};
|
||||||
for (int bytesRead = 0; bytesRead < SECOND_PAGE_MAX_LENGTH; bytesRead++) {
|
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)) {
|
if (bufferMatches(buffer, oggPageHeader, bytesRead)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +107,7 @@ public abstract class VorbisCommentReader {
|
||||||
* Looks for an identification header in the first page of the file. If an
|
* Looks for an identification header in the first page of the file. If an
|
||||||
* identification header is found, it will be skipped completely
|
* 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];
|
byte[] buffer = new byte[FIRST_OPUS_PAGE_LENGTH];
|
||||||
IOUtils.readFully(input, buffer);
|
IOUtils.readFully(input, buffer);
|
||||||
final byte[] oggIdentificationHeader = new byte[]{ PACKET_TYPE_IDENTIFICATION, 'v', 'o', 'r', 'b', 'i', 's' };
|
final byte[] oggIdentificationHeader = new byte[]{ PACKET_TYPE_IDENTIFICATION, 'v', 'o', 'r', 'b', 'i', 's' };
|
||||||
|
@ -115,6 +119,7 @@ public abstract class VorbisCommentReader {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throw new IOException("No vorbis identification header found");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findCommentHeader(InputStream input) throws IOException {
|
private void findCommentHeader(InputStream input) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue