GHSL-2025-054: Use After Free (UAF) in Poppler - CVE-2025-52886
Poppler uses a 32-bit atomic integer for reference counting, which can overflow and cause a use-after-free. An attacker could potentially exploit this to achieve code execution, though triggering it took 12 hours in testing.
Originally disclosed on GitHub Security Lab
poppler uses std::atomicint for reference counting. Because it is only 32 bits, it is possible to overflow the reference count and trigger a use-after-free.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Poppler is the PDF rendering library used by many open-source PDF tools, including pdftohtml. Like many C++ codebases that manage shared objects, it uses reference counting to decide when an object can be freed. When the last reference to an object is released, the object is deleted.
Poppler implements those counters with std::atomic_int. That type is 32 bits wide, so a counter can only represent values up to 0x7fffffff before it wraps. The report shows that a crafted PDF can drive one of these counters all the way around to zero, causing an object to be freed while references to it still exist: a use-after-free.
The issue is tracked as GHSL-2025-054 and CVE-2025-52886, and was tested against poppler 25.02.0.
Setup
The only tool needed to reproduce the issue is poppler's own pdftohtml binary, built from the tested version. The proof-of-concept file is a PDF of about 3.1KB. No accounts, roles or special configuration are involved: the input is a single file passed to a command-line tool.
Finding it
poppler uses std::atomic_int for reference counting in four places:
Annot.hArray.hDict.hStream.h
Because std::atomic_int is only 32 bits, any one of these reference counts can be overflowed. An overflowed reference count can reach zero (or wrap past it) while live references remain, which leads to the object being deleted and then used: a use-after-free memory corruption vulnerability.
The proof of concept targets the counter in Annot.h.
Exploitation
Step 1: Build a PDF that inflates into a huge annotation array
The PoC file is only 3.1KB, but it contains a stream which decompresses to an array of annotations of size 0x1000000. The compression keeps the file small while the in-memory structure is enormous.
Step 2: Reference the array from many pages
That array is referenced by 0x100 pages. Each page reference increments the reference count on the annotation, so the counter is incremented 0x100000000 times in total. Since the counter is 32 bits, it wraps around to zero, and the annotation is deleted even though it is still in use.
Step 3: Trigger the code path
Run the PoC through pdftohtml:
pdftohtml GHSL-2025-054_poppler_refcount.pdf
The command processes the crafted PDF; in the researcher's testing, triggering the use-after-free took 12 hours. In the researcher's testing, triggering it took 12 hours.
Root cause
The mistake is the width of the reference counters. std::atomic_int is 32 bits, and poppler uses it for reference counting in Annot.h, Array.h, Dict.h and Stream.h. A 32-bit counter can be wrapped by an input that causes enough increments, and once it wraps to zero the object is freed while references to it remain. The report does not describe any additional defence that would have caught the wrap.
Impact
It is possible that this use-after-free could be exploited to achieve code execution in poppler. However, in the researcher's testing it took 12 hours to trigger the use-after-free, so in practice the risk of exploitation is low. The issue is classified under CWE-190 (Integer Overflow or Wraparound), CWE-416 (Use After Free) and CWE-911 (Improper Update of Reference Count).
Fix
The issue was fixed by limiting the maximum number of annots. The fix landed in merge request 1828 on 2025-06-02, and poppler 25.06.0, released on 2025-06-03, contains it.
Variants to test
The report identifies three other reference counters using the same 32-bit type: those in Array.h, Dict.h and Stream.h.
Hunting notes
This kind of bug hides in C++ codebases that hand-roll reference counting with fixed-width integer types, particularly parsers for complex file formats where one input object can be referenced from many places.
Coordinated disclosure timeline
- 2025-04-03: Reported as a private issue.
- 2025-06-02: Fixed by limiting the maximum number of annots.
- 2025-06-03: Issue made publicly visible.
- 2025-06-03: Poppler 25.06.0 released.
Credit
This issue was discovered and reported by GHSL team member @kevinbackhouse (Kevin Backhouse).
What happened, in plain words
A security researcher found a bug in Poppler, a piece of software that many programs use to read PDF files. The bug can make a program free up a piece of memory and then keep using it, which is a dangerous situation called a use-after-free. The cause is a counter that keeps track of how many things are using a piece of memory. That counter has a fixed maximum size, and a carefully built PDF file can push it past that maximum so it wraps back round to zero. When the counter says zero, the program thinks nobody needs the memory any more and deletes it, even though it is still in use.
The bug is tracked as GHSL-2025-054 and CVE-2025-52886. It was tested against Poppler version 25.02.0. The researcher built a tiny PDF file, about 3.1KB, that triggers the problem. In testing it took 12 hours to actually trigger, so the practical risk is considered low, but the bug is real and was fixed in Poppler 25.06.0.
Background: what Poppler is and what reference counting means
Poppler is a library, meaning a collection of code that other programs can reuse. It is the part that actually reads and understands PDF files. Many open-source PDF tools rely on it, including pdftohtml, a command-line program that converts a PDF into HTML so it can be viewed in a browser.
When a program works with PDFs, it creates objects in memory: pages, annotations (things like comments or highlights attached to a page), arrays, dictionaries and streams. Several parts of the program may need the same object at the same time. The program has to know when it is safe to delete an object, because deleting something that is still being used causes crashes or worse.
A common solution is reference counting. Think of it like a library book with a sign-out sheet. Every time someone borrows the book, a tally goes up by one. Every time someone returns it, the tally goes down by one. When the tally reaches zero, the book goes back on the shelf. In software, the object is deleted when its counter reaches zero.
Poppler stores these counters using a C++ type called std::atomic_int. "Atomic" means the counter can be safely changed by multiple parts of a program at once without getting confused. "Int" means it is a whole number. The important detail is that this type is 32 bits wide. A 32-bit counter can only hold values up to 0x7fffffff (about 2.1 billion). If you add one more, it does not error out; it wraps around to a negative number and keeps going. This wrapping is called an integer overflow or wraparound.
If a counter wraps all the way round to zero while references to the object still exist, the program deletes the object. Anything still holding a reference now points at freed memory. Using that memory afterwards is the use-after-free bug.
The disclosure timeline
The report lists these dates:
- 2025-04-03: Reported as a private issue.
- 2025-06-02: Fixed by limiting the maximum number of annots.
- 2025-06-03: Issue made publicly visible.
- 2025-06-03: Poppler 25.06.0 released.
"Private issue" means the bug report was visible only to the maintainers at first, so they had time to fix it before attackers could read about it. "Annots" is short for annotations, the comments and marks attached to PDF pages.
Finding the bug
Poppler uses std::atomic_int for reference counting in four places:
Annot.hArray.hDict.hStream.h
These are header files, files that declare how parts of the program are built. Each one contains a counter of the same 32-bit type. Because the type is only 32 bits, any one of these counters can be overflowed. When a counter overflows and reaches zero while live references remain, the object is deleted and then used, which is the use-after-free memory corruption vulnerability.
The proof of concept targets the counter in Annot.h, the one that counts references to annotations.
How the proof of concept works
Step 1: A small file that expands into a huge structure
The proof-of-concept file is only 3.1KB, but it contains a stream which decompresses to an array of annotations of size 0x1000000. A stream in a PDF is a block of data, often compressed. Compression is like vacuum-packing clothes: the packed bag is small, but when you open it the contents take up a lot of room. Here the file on disk is tiny, but when Poppler decompresses it, the array in memory is enormous. 0x1000000 is hexadecimal notation for 16,777,216, so the array holds over sixteen million annotations.
Step 2: Many pages point at the same array
That array is referenced by 0x100 pages. 0x100 is hexadecimal for 256. Each page reference increments the reference count on the annotation. So the counter is incremented 0x100000000 times in total. 0x100000000 is 4,294,967,296, which is exactly 2 to the power of 32, the point at which a 32-bit counter wraps back to zero. Since the counter is 32 bits, it wraps around to zero, and the annotation is deleted even though it is still in use.
In everyday terms: imagine a tally sheet that only has room for a certain number of marks. Once you make one mark too many, the sheet resets to blank. Anyone reading the blank sheet concludes the item is no longer needed, even though people are still holding it.
Step 3: Run the file through the tool
The researcher ran the crafted PDF through pdftohtml:
pdftohtml GHSL-2025-054_poppler_refcount.pdf
Line by line:
pdftohtmlis the name of the program being run. It is Poppler's tool that converts a PDF into HTML.GHSL-2025-054_poppler_refcount.pdfis the name of the input file, the crafted PDF that triggers the bug.
Running this command processes the PDF; in the researcher's testing, triggering the use-after-free took 12 hours. In the researcher's testing, triggering it took 12 hours.
Why the bug happens
The root cause is the width of the reference counters. std::atomic_int is 32 bits, and Poppler uses it for reference counting in Annot.h, Array.h, Dict.h and Stream.h. A 32-bit counter can be wrapped by an input that causes enough increments. Once it wraps to zero, the object is freed while references to it remain. The report does not describe any additional defence that would have caught the wrap.
What the impact is
It is possible that this use-after-free could be exploited to achieve code execution in Poppler. Code execution means an attacker could make the program run their own instructions, which is the most serious kind of software bug. However, in the researcher's testing it took 12 hours to trigger the use-after-free, so in practice the risk of exploitation is low. The issue is classified under three weakness categories:
- CWE-190: Integer Overflow or Wraparound
- CWE-416: Use After Free
- CWE-911: Improper Update of Reference Count
CWE stands for Common Weakness Enumeration, a public catalogue that gives standard names to kinds of software mistakes.
How it was fixed
The issue was fixed by limiting the maximum number of annots. In other words, the program now limits the maximum number of annotations. The fix landed in merge request 1828 on 2025-06-02, and Poppler 25.06.0, released on 2025-06-03, contains it.
Other places to check
The report identifies three other reference counters using the same 32-bit type: those in Array.h, Dict.h and Stream.h. A sanitiser is a special build of a program that watches for memory mistakes and reports them loudly instead of letting them pass silently.
Notes for people hunting similar bugs
This kind of bug hides in C++ codebases that hand-roll reference counting with fixed-width integer types, particularly parsers for complex file formats where one input object can be referenced from many places.
Credit
This issue was discovered and reported by GHSL team member @kevinbackhouse (Kevin Backhouse).
Glossary
- Poppler: A library that reads and renders PDF files, used by many open-source PDF tools.
- Library: A collection of reusable code that other programs build on.
- PDF: Portable Document Format, a file format for documents that look the same on any device.
pdftohtml: A command-line program from Poppler that converts a PDF into HTML.- Object: A chunk of data in a program's memory that represents something, such as a page or an annotation.
- Annotation: A comment, highlight or other mark attached to a PDF page.
- Reference counting: A technique where a counter tracks how many parts of a program are using an object; the object is deleted when the count reaches zero.
std::atomic_int: A C++ whole-number type that can be safely changed by multiple parts of a program at once; it is 32 bits wide.- 32-bit: A number size that can hold values up to about 2.1 billion before wrapping.
- Integer overflow / wraparound: When a counter goes past its maximum and resets to a low or negative value instead of erroring.
- Use-after-free: A bug where a program deletes a piece of memory and then keeps using it.
- Memory corruption: Damage to a program's memory that can cause crashes or let an attacker take control.
- Code execution: When an attacker manages to make a program run their own instructions.
- Stream: A block of data inside a PDF, often compressed.
- Compression: Storing data in a smaller form that expands back to its full size when read.
- Hexadecimal: A way of writing numbers using base 16, often prefixed with
0x. - CWE: Common Weakness Enumeration, a public catalogue of standard names for kinds of software weaknesses.
- Sanitiser: A special build of a program that detects and reports memory errors.
- Merge request: A proposal to add changes to a code project, which maintainers review before accepting.
- Recon: Short for reconnaissance, the early stage of security research where you study a target for weaknesses.