Skip to content

Commit

Permalink
Merge pull request #2068 from JeromeMartinez/RIFF_SubElements_Check
Browse files Browse the repository at this point in the history
Conformance checker: check of RIFF sub-element sizes
  • Loading branch information
JeromeMartinez authored Jun 10, 2024
2 parents cfa57fe + 0b7f948 commit f589d67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 6 additions & 2 deletions Source/MediaInfo/Multiple/File_Riff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,12 @@ bool File_Riff::Header_Begin()
Element_Begin1("...Continued");
Element_ThisIsAList();
if (Buffer_DataToParse_End)
{
Header_Fill_Code(0x64617461);
Header_Fill_Size(Buffer_DataToParse_End-(File_Offset+Buffer_Offset));
if (Buffer_DataToParse_End>File_Size)
Buffer_DataToParse_End=File_Size; // Done here for at least one conformance check of the value. TODO: better handling
}
else
Header_Fill_Size(Element_Size);
Element_End();
Expand Down Expand Up @@ -1092,8 +1097,7 @@ void File_Riff::Header_Parse()
if (File_Offset+Buffer_Offset+8+Size_Complete>File_Size)
{
if (Element_Level<=2) //Incoherencies info only at the top level chunk
IsTruncated(File_Offset+Buffer_Offset+8+Size_Complete, Element_Offset!=8, "RIFF");
Size_Complete=File_Size-(File_Offset+Buffer_Offset+Element_Offset);
IsTruncated(File_Offset+Buffer_Offset+8+Size_Complete, Element_Offset!=8, Ztring().From_CC4(Name).Trim().To_UTF8().c_str());
}

//Alignment
Expand Down
12 changes: 7 additions & 5 deletions Source/MediaInfo/Multiple/File_Riff_Elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,7 +3425,7 @@ void File_Riff::RMP3_data()
{
Element_Name("Raw datas");

Fill(Stream_Audio, StreamPos_Last, Audio_StreamSize, Buffer_DataToParse_End-Buffer_DataToParse_Begin);
Fill(Stream_Audio, StreamPos_Last, Audio_StreamSize, Buffer_DataToParse_End?((Buffer_DataToParse_End>File_Size?File_Size:Buffer_DataToParse_End)-Buffer_DataToParse_Begin):(Element_TotalSize_Get()-Alignement_ExtraByte));
Stream_Prepare(Stream_Audio);

//Creating parser
Expand All @@ -3440,7 +3440,7 @@ void File_Riff::RMP3_data()
StreamItem.Parsers.push_back(Parser);
#else //MEDIAINFO_MPEG4_YES
Fill(Stream_Audio, StreamPos_Last, Audio_Format, "MPEG Audio");
Skip_XX(Buffer_DataToParse_End-Buffer_DataToParse_Begin, "Data");
Skip_XX(Buffer_DataToParse_End?((Buffer_DataToParse_End>File_Size?File_Size:Buffer_DataToParse_End)-Buffer_DataToParse_Begin):(Element_TotalSize_Get()-Alignement_ExtraByte), "Data");
#endif
}

Expand Down Expand Up @@ -3741,7 +3741,7 @@ void File_Riff::WAVE_axml()
Element_Name("AXML");

//Parsing
Adm->TotalSize=Buffer_DataToParse_End?(Buffer_DataToParse_End-(File_Offset+Buffer_Offset)):Element_TotalSize_Get();
Adm->TotalSize=Buffer_DataToParse_End?((Buffer_DataToParse_End>File_Size?File_Size:Buffer_DataToParse_End)-Buffer_DataToParse_Begin):(Element_TotalSize_Get()-Alignement_ExtraByte);
WAVE_axml_Continue();
}
}
Expand Down Expand Up @@ -3992,15 +3992,15 @@ void File_Riff::WAVE_data()

if (Buffer_DataToParse_End && Buffer_DataToParse_End-Buffer_DataToParse_Begin<100)
{
Skip_XX(Buffer_DataToParse_End-Buffer_Offset, "Unknown");
Skip_XX(Buffer_DataToParse_End-Alignement_ExtraByte-Buffer_Offset, "Unknown");
return; //This is maybe embeded in another container, and there is only the header (What is the junk?)
}

//Parsing
Element_Code=(int64u)-1;

FILLING_BEGIN();
int64u StreamSize=(Buffer_DataToParse_End?(Buffer_DataToParse_End-Buffer_DataToParse_Begin):Element_Size)-(Element_Code==Elements::AIFF_SSND?8:0);
int64u StreamSize=(Buffer_DataToParse_End?((Buffer_DataToParse_End>File_Size?File_Size:Buffer_DataToParse_End)-Buffer_DataToParse_Begin):(Element_TotalSize_Get()-Alignement_ExtraByte))-(Element_Code==Elements::AIFF_SSND?8:0);
Fill(Stream_Audio, StreamPos_Last, Audio_StreamSize, StreamSize, 10, true);
if (Retrieve(Stream_Audio, StreamPos_Last, Audio_Format)==__T("PCM") && BlockAlign)
Fill(Stream_Audio, StreamPos_Last, Audio_SamplingCount, StreamSize/BlockAlign, 10, true);
Expand All @@ -4022,6 +4022,8 @@ void File_Riff::WAVE_data()
Fill(Stream_General, 0, General_Duration, Retrieve_Const(Stream_General, 0, General_Duration).To_int64u()+Duration, 0, true); // Found files with 2 fmt/data chunks
Fill(Stream_Audio, StreamPos_Last, Audio_Duration, Duration, 0, true);
}
if (!Buffer_DataToParse_End)
WAVE_data_Continue();
FILLING_END();
}

Expand Down

0 comments on commit f589d67

Please sign in to comment.