cosmetics and fixed a head overflow.

This commit is contained in:
Damiano Galassi committed 2018-11-22 15:28:32 +01:00
1 parent d7f2d6ebba
commit a32f84002e
1 file changed
+13 -7
+13 -7
View File
@@ -897,7 +897,7 @@ int analyze_EAC3(void **context, uint8_t *frame, uint32_t size)
while (cumul_size != size) { while (cumul_size != size) {
int i; int i;
CMemoryBitstream gbc; CMemoryBitstream gbc;
gbc.SetBytes(frame + cumul_size, (size - cumul_size) * 8); gbc.SetBytes(frame + cumul_size, (size - cumul_size));
if (ac3_parse_header(gbc, &hdr) < 0) { if (ac3_parse_header(gbc, &hdr) < 0) {
free(hdr); free(hdr);
return -1; return -1;
@@ -1283,7 +1283,9 @@ bool parse_ac3_emdf(CMemoryBitstream &b, AC3HeaderInfo *hdr)
//Could use CMemoryBitstream.PutBytes() to create a copy of CMBS //Could use CMemoryBitstream.PutBytes() to create a copy of CMBS
uint16_t emdf_sync = b.GetBits(16); //syncword 0x5838 uint16_t emdf_sync = b.GetBits(16); //syncword 0x5838
if (emdf_sync != 0x5838) { if (emdf_sync != 0x5838) {
#ifdef DEBUG_PARSER
printf("WTF"); printf("WTF");
#endif
} }
uint32_t emdf_container_length = b.GetBits(16) * 8; //emdf_container_length uint32_t emdf_container_length = b.GetBits(16) * 8; //emdf_container_length
//bool have_oamd = false, have_joc = false; //for the lack of better, lets expect only sequence OAMD-JOC-END //bool have_oamd = false, have_joc = false; //for the lack of better, lets expect only sequence OAMD-JOC-END
@@ -1385,20 +1387,24 @@ bool parse_ac3_emdf(CMemoryBitstream &b, AC3HeaderInfo *hdr)
//Atmos in E-AC-3 is detected by looking for OAMD payload (see ETSI TS 103 420) //Atmos in E-AC-3 is detected by looking for OAMD payload (see ETSI TS 103 420)
// in EMDF container in skipfld inside audblk() of E-AC-3 frame (see ETSI TS 102 366) // in EMDF container in skipfld inside audblk() of E-AC-3 frame (see ETSI TS 102 366)
void analyze_ac3_skipfld(CMemoryBitstream &b, AC3HeaderInfo *hdr) void analyze_ac3_skipfld(CMemoryBitstream &b, AC3HeaderInfo *hdr)
{ //Let's take a look at frame's auxdata() {
//Let's take a look at frame's auxdata()
uint16_t emdf_syncword; uint16_t emdf_syncword;
if(hdr->bitstream_id != 16) if (hdr->bitstream_id != 16) {
return; return;
while(b.GetRemainingBits() > 16) { }
while (b.GetRemainingBits() > 16) {
emdf_syncword = b.PeakBits(16); emdf_syncword = b.PeakBits(16);
if(emdf_syncword == 0x5838) { //NB! b.head still points to emdf syncword because we peeked and did not get the bits! if (emdf_syncword == 0x5838) { //NB! b.head still points to emdf syncword because we peeked and did not get the bits!
#ifdef DEBUG_PARSER #ifdef DEBUG_PARSER
printf("parsing bitstream_id: 0x%X frame_type: 0x%0X substreamid: 0x%0X\n", hdr->bitstream_id, hdr->frame_type, hdr->substreamid); printf("parsing bitstream_id: 0x%X frame_type: 0x%0X substreamid: 0x%0X\n", hdr->bitstream_id, hdr->frame_type, hdr->substreamid);
printf("SKIPFLD: found EMDF syncword 0x%x at bit pos: 0x%0x (%d)\n", emdf_syncword, b.GetBitPosition(), b.GetBitPosition()); printf("SKIPFLD: found EMDF syncword 0x%x at bit pos: 0x%0x (%d)\n", emdf_syncword, b.GetBitPosition(), b.GetBitPosition());
#endif #endif
if(parse_ac3_emdf(b, hdr)) if (parse_ac3_emdf(b, hdr)) {
break; break;
}
// else //false positive // else //false positive
// b.SkipBits(1); // b.SkipBits(1);
} else { } else {
@@ -1420,7 +1426,7 @@ void analyze_ac3_auxdata(CMemoryBitstream &b, AC3HeaderInfo *hdr)
simply look to the end of the AC-3 syncframe to find auxdatal, backup auxdatal bits (from the beginning of auxdatal) simply look to the end of the AC-3 syncframe to find auxdatal, backup auxdatal bits (from the beginning of auxdatal)
in the data stream, and then unpack auxdatal bits moving forward in the data stream. in the data stream, and then unpack auxdatal bits moving forward in the data stream.
*/ */
if(b.GetBits(1)) { //auxdatae if (b.GetBits(1)) { //auxdatae
b.SkipBits(-14); //back up to beginning of auxdatal field b.SkipBits(-14); //back up to beginning of auxdatal field
auxdatal = b.GetBits(14); //auxdatal auxdatal = b.GetBits(14); //auxdatal
b.SkipBits(-auxdatal); //back up to beginning of auxdatal payload b.SkipBits(-auxdatal); //back up to beginning of auxdatal payload