mirror of
https://github.com/samsonjs/media.git
synced 2026-04-19 13:35:47 +00:00
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
This commit is contained in:
parent
034209c5a2
commit
febb8c589e
2 changed files with 11 additions and 3 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue