Commit febb8c58 by andrewlewis Committed by Oliver Woodman

Improve handling of failed NAL prefix reads

nalPrefix.readUnsignedIntToInt() will throw if the unsigned output doesn't fit
in an int. Before this change, in the error case we'd retry reading from after
the NAL prefix position. Throw a ParserException so that reading an obviously
invalid NAL prefix will be treated as a fatal exception by the default load
error handling policy.

PiperOrigin-RevId: 236839690
parent 034209c5
......@@ -1251,7 +1251,11 @@ public class FragmentedMp4Extractor implements Extractor {
// Read the NAL length so that we know where we find the next one, and its type.
input.readFully(nalPrefixData, nalUnitLengthFieldLengthDiff, nalUnitPrefixLength);
nalPrefix.setPosition(0);
sampleCurrentNalBytesRemaining = nalPrefix.readUnsignedIntToInt() - 1;
int nalLengthInt = nalPrefix.readInt();
if (nalLengthInt < 1) {
throw new ParserException("Invalid NAL length");
}
sampleCurrentNalBytesRemaining = nalLengthInt - 1;
// Write a start code for the current NAL unit.
nalStartCode.setPosition(0);
output.sampleData(nalStartCode, 4);
......
......@@ -520,9 +520,13 @@ public final class Mp4Extractor implements Extractor, SeekMap {
while (sampleBytesWritten < sampleSize) {
if (sampleCurrentNalBytesRemaining == 0) {
// Read the NAL length so that we know where we find the next one.
input.readFully(nalLength.data, nalUnitLengthFieldLengthDiff, nalUnitLengthFieldLength);
input.readFully(nalLengthData, nalUnitLengthFieldLengthDiff, nalUnitLengthFieldLength);
nalLength.setPosition(0);
sampleCurrentNalBytesRemaining = nalLength.readUnsignedIntToInt();
int nalLengthInt = nalLength.readInt();
if (nalLengthInt < 0) {
throw new ParserException("Invalid NAL length");
}
sampleCurrentNalBytesRemaining = nalLengthInt;
// Write a start code for the current NAL unit.
nalStartCode.setPosition(0);
trackOutput.sampleData(nalStartCode, 4);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment