Skip to content

Commit d89e381

Browse files
committed
#262: recursion on object parsing. avoid with stroing the current path as parser state and identifying cyces
1 parent c52cd63 commit d89e381

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

PDFWriter/PDFParser.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void PDFParser::ResetParser()
8585
mObjectStreamsCache.clear();
8686
mDecryptionHelper.Reset();
8787
mParsedXrefs.clear();
88+
mNewObjectParsingPath.Reset();
8889

8990
}
9091

@@ -721,16 +722,26 @@ PDFObject* PDFParser::ParseNewObject(ObjectIDType inObjectId)
721722
{
722723
return NULL;
723724
}
724-
else if(eXrefEntryExisting == mXrefTable[inObjectId].mType)
725+
726+
// cycle check in
727+
if(mNewObjectParsingPath.EnterObject(inObjectId) != eSuccess)
728+
return NULL;
729+
730+
if(eXrefEntryExisting == mXrefTable[inObjectId].mType)
725731
{
726732
return ParseExistingInDirectObject(inObjectId);
727733
}
728-
else if(eXrefEntryStreamObject == mXrefTable[inObjectId].mType)
734+
735+
if(eXrefEntryStreamObject == mXrefTable[inObjectId].mType)
729736
{
730737
return ParseExistingInDirectStreamObject(inObjectId);
731738
}
732-
else
739+
740+
// cycle check out
741+
if(mNewObjectParsingPath.ExitObject(inObjectId) != eSuccess)
733742
return NULL;
743+
744+
return NULL;
734745
}
735746

736747
ObjectIDType PDFParser::GetObjectsCount()

PDFWriter/PDFParser.h

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class PDFParser
178178
DecryptionHelper mDecryptionHelper;
179179
InputOffsetStream mStream;
180180
AdapterIByteReaderWithPositionToIReadPositionProvider mCurrentPositionProvider;
181+
PDFParsingPath mNewObjectParsingPath;
181182

182183
// we'll use this items for bacwkards reading. might turns this into a proper stream object
183184
IOBasicTypes::Byte mLinesBuffer[LINE_BUFFER_SIZE];

PDFWriter/PDFParsingPath.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ std::string PDFParsingPath::PrintPath() {
6666

6767
if(it != mObjectsPath.end()) {
6868
pathWriter<<*it;
69+
++it;
6970
for(; it != mObjectsPath.end(); ++it) {
7071
pathWriter<<", "<<*it;
7172
}

PDFWriterTesting/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ endforeach ()
114114
file(GLOB fuzztestfiles ${CMAKE_CURRENT_SOURCE_DIR}/Materials/fuzzing/*)
115115
foreach (fuzztestfile ${fuzztestfiles})
116116
get_filename_component (TName ${fuzztestfile} NAME)
117-
add_test (NAME FuzzTest_${TName} COMMAND PDFWriterTesting PDFParserFuzzSanity ${CMAKE_CURRENT_SOURCE_DIR}/Materials ${CMAKE_BINARY_DIR}/Testing/Output ${fuzztestfile})
117+
add_test (NAME FuzzTest_${TName} COMMAND PDFWriterTesting PDFParserFuzzSanity ${CMAKE_CURRENT_SOURCE_DIR}/Materials ${CMAKE_BINARY_DIR}/Testing/Output ${fuzztestfile} FuzzTest_${TName}.txt)
118118
endforeach ()
119119

120120

Binary file not shown.

PDFWriterTesting/PDFParserFuzzSanity.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int PDFParserFuzzSanity(int argc, char* argv[]) {
2323
}
2424

2525
// traces on
26-
Trace::DefaultTrace().SetLogSettings(BuildRelativeOutputPath(argv, "PDFParserFuzzSanity.txt"), true, true);
26+
Trace::DefaultTrace().SetLogSettings(BuildRelativeOutputPath(argv, argv[4]), true, true);
2727

2828
// checks that returns, status doesn't matter
2929
parser.StartPDFParsing(pdfFile.GetInputStream());

0 commit comments

Comments
 (0)