@@ -574,8 +574,7 @@ private void parseAdtsHeader() throws ParserException {
574
574
}
575
575
576
576
@ RequiresNonNull ("currentOutput" )
577
- void readAacProgramConfigElement () {
578
- Format pendingOutputFormat = checkNotNull (this .pendingOutputFormat );
577
+ private void readAacProgramConfigElement () throws ParserException {
579
578
ParsableBitArray pceBuffer = checkNotNull (this .pceBuffer );
580
579
581
580
// See ISO 13818-7 Advanced Audio Coding (2006) Table 36 for PCE tag encoding.
@@ -614,37 +613,40 @@ void readAacProgramConfigElement() {
614
613
int commentSizeBits = 8 ; // comment_field_bytes
615
614
616
615
// Beyond this point, pceBuffer may be empty, so check before consuming.
617
- if (pceBuffer .bitsLeft () >= channelBits + numAlignmentBits + commentSizeBits ) {
618
- pceBuffer .skipBits (channelBits );
616
+ if (pceBuffer .bitsLeft () < channelBits + numAlignmentBits + commentSizeBits ) {
617
+ throw ParserException .createForMalformedContainer (/* message= */ null , /* cause= */ null );
618
+ }
619
619
620
- // Store PCE size excluding initial PCE tag, alignment bits and comment for later.
621
- int numPceBits = pceBuffer .getPosition () - 3 /* PCE tag */ ;
620
+ pceBuffer .skipBits (channelBits );
622
621
623
- pceBuffer .skipBits (numAlignmentBits );
624
- int commentSize = pceBuffer .readBits (commentSizeBits );
622
+ // Store PCE size excluding initial PCE tag, alignment bits and comment for later.
623
+ int numPceBits = pceBuffer .getPosition () - 3 /* PCE tag */ ;
624
+ pceBuffer .skipBits (numAlignmentBits );
625
+ int commentSize = pceBuffer .readBits (commentSizeBits );
625
626
626
- if (sampleSize >= pceBuffer .getBytePosition () + commentSize ) {
627
- // Append PCE to format's audio specific config.
628
- byte [] oldConfig = pendingOutputFormat . initializationData . get ( 0 );
627
+ if (sampleSize < pceBuffer .getBytePosition () + commentSize ) {
628
+ throw ParserException . createForMalformedContainer ( /* message= */ null , /* cause= */ null );
629
+ }
629
630
630
- int configSize = oldConfig .length ;
631
- configSize += (numPceBits + 7 ) / 8 + 1 ; // Byte align and add a zero length comment.
632
- byte [] newConfig = Arrays .copyOf (oldConfig , configSize );
631
+ Format pendingOutputFormat = checkNotNull (this .pendingOutputFormat );
632
+ // Append PCE to format's audio specific config.
633
+ byte [] oldConfig = pendingOutputFormat .initializationData .get (0 );
634
+ int configSize = oldConfig .length ;
635
+ configSize += (numPceBits + 7 ) / 8 + 1 ; // Byte align and add a zero length comment.
636
+ byte [] newConfig = Arrays .copyOf (oldConfig , configSize );
633
637
634
- pceBuffer .setPosition (3 /* PCE tag */ );
635
- pceBuffer .readBits (newConfig , oldConfig .length , numPceBits );
638
+ pceBuffer .setPosition (3 /* PCE tag */ );
639
+ pceBuffer .readBits (newConfig , oldConfig .length , numPceBits );
636
640
637
- pendingOutputFormat =
638
- pendingOutputFormat
639
- .buildUpon ()
640
- .setInitializationData (ImmutableList .of (newConfig ))
641
- .build ();
641
+ pendingOutputFormat =
642
+ pendingOutputFormat
643
+ .buildUpon ()
644
+ .setInitializationData (ImmutableList .of (newConfig ))
645
+ .build ();
642
646
643
- // Submit PCE-appended output format.
644
- currentOutput .format (pendingOutputFormat );
645
- hasOutputFormat = true ;
646
- }
647
- }
647
+ // Submit PCE-appended output format.
648
+ this .currentOutput .format (pendingOutputFormat );
649
+ this .hasOutputFormat = true ;
648
650
}
649
651
650
652
// Pass through all accumulated data as sample data.
0 commit comments