Skip to content

Infinite loop in PdfDocument::InsertDocumentPageAt #76

Description

@kovidgoyal

In the loop at line 219

    for (auto& obj : GetObjects())
    {
        PdfReference ref(static_cast<uint32_t>(obj->GetIndirectReference().ObjectNumber() + difference), obj->GetIndirectReference().GenerationNumber());
        auto newObj = new PdfObject(PdfDictionary());
        newObj->setDirty();
        newObj->SetIndirectReference(ref);
        m_Objects.PushObject(newObj);
        *newObj = *obj;

        PoDoFo::LogMessage(PdfLogSeverity::Information, "Fixing references in {} {} R by {}",
            newObj->GetIndirectReference().ObjectNumber(), newObj->GetIndirectReference().GenerationNumber(), difference);
        fixObjectReferences(*newObj, difference);
    }

You are looping over m_Objects while adding objects to it in the body of the loop. I can never remember all the semantics of C++ iterator invalidation, but that seems unlikely to be correct. And in practice i have observed that calling that function hangs in that loop, looping till out of memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpatch welcomeA patch for this issue is welcomevulnerabilitySecurity related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions