Getting a photo on Nextcloud (an open-source platform organizations host on their own servers to store, share and collaborate on files) is all fun and games, until that photo turns out to be a trap, not the team offsite pic you were expecting.
Nothing looks wrong. But behind that thumbnail, the server has already run a command hidden inside the photo, with access to every file and user on it. (Yes, your company’s files included.)
It started with Hacktron’s “HEIF Heist,” which showed that one malicious image could break into a production system at OpenAI. The root cause was a low-level C++ image parser, the kind of code that sits deep in the stack and that almost no one watches, so we went looking for other major platforms shipping the same kind of code. That search led us to Nextcloud.
The bug sat four layers deep, in an image library Nextcloud never chose, filed for months as “just a crash.” With AI in the loop, we turned it into remote code execution in days. Nextcloud is just an example: every stack has dependencies like this.
Here’s how the chain works, how it was fixed, and what to check in yours.
TL;DR
We found unauthenticated remote code execution in Nextcloud’s HEIC image previews. A single crafted file, shared as a public link, runs a command on the server as www-data, the user that owns every file on the instance. It is zero-click against a remote instance an attacker can reach, and one click on a local deployment. The affected Nextcloud Docker images have over a billion pulls on Docker Hub, so the blast radius is large.
- Modern exploitation: after Hacktron’s HEIF Heist broke into a production system at OpenAI, we set out to see how far the same pattern reaches. With AI models in the loop, a chain that would once take weeks came together in days, lowering the barrier for researchers and attackers alike.
- The bug: CVE-2026-49346, an integer overflow in libde265, the low-level decoder beneath libheif and ImageMagick. It was published as nothing more than a crash.
- The exploit: we turn that crash into a controlled memory write, aim it with a heap spray, and hijack the decoder’s own teardown into calling
system(), all with ASLR on. The full chain follows below. - The fix: fully patched and verified. The current fpm-alpine images (32–35) dropped the decode path, and Alpine 3.24 ships fixed libraries.
Modern Exploitation
The chain you’re about to read is not simple. It crosses four libraries, needs heap grooming tuned to PHP-FPM’s musl allocator, defeats two safety checks, reuses a gadget found inside libheif, and recovers randomized addresses under ASLR. A few years ago, assembling that was weeks of specialized work, the kind reserved for dedicated vulnerability-research teams. That cost is a big part of why most “just a crash” bugs were left alone.
That is changing. AI models are becoming a standard tool in offensive research, and what they change is time. Turning a memory bug into a working exploit is a loop: form a hypothesis about the allocator or the decoder, test it, read the result, adjust. That loop runs hundreds of times across layers that interact in non-obvious ways. A capable model runs that loop far faster: it maps unfamiliar code, proposes and checks hypotheses, and follows how a single corruption propagates through a multi-library chain in a fraction of the time it takes by hand. What used to gate serious exploitation behind weeks of expert effort now fits in days. That speed is what made this chain practical, taking a bug dismissed as “just a crash” and showing how far it actually reaches.
We stayed in the loop throughout. The models helped us move faster inside it by shaping and testing the ideas we thought would work, discarding the ones that didn’t, and tightening each pass. The direction and the judgment stayed ours. The models didn’t change who does the work. They changed how long it takes.
The impact reaches past this one bug: as models take on the specialized work, exploitation that once required a few expert teams spreads to many more hands, and time-to-exploit keeps shrinking. The threat is concrete. The window an attacker needs between a bug going public and a working exploit in hand is collapsing, so more vulnerabilities become real attacks, in more hands, faster than defenders can patch or even triage them.
Building the exploit is only half of it. AI agents can deliver it too. In Skill2Exploit, we show how an innocent meme-finder skill makes an agent fetch this same poisoned HEIC and drop it onto a company’s Nextcloud server, where the preview runs it. Scanners pass every piece, because no piece is malicious on its own.
The Attack Chain in a Nutshell
Before diving into the details, here’s the full exploit in plain language:
- The entry point: A visitor opens a public Nextcloud share link. The page requests a thumbnail, and Nextcloud hands the HEIC file down a four-layer chain: ImageMagick, then libheif, then libde265, a C++ video decoder far below the app.
- The bug: libde265 sizes the image buffer with 32-bit math. Chosen dimensions make that size too large for a 32-bit number, so it wraps to a tiny value. The decoder allocates the tiny buffer, then writes the full image into it, far past the end. That is an out-of-bounds write.
- The precision: HEVC’s PCM coding mode makes the overflow bytes exactly what the attacker put in the file. The result is a controlled write of chosen values to chosen places.
- The bypasses: A decoder should reject an image this large first. The file hides its real size by putting small, legal dimensions where the check looks and oversized ones only where the decoder reads. It slips past the limit and reaches the bug.
- The payload: The overflow swaps a C++ smart pointer for a fake one. ImageMagick’s error triggers cleanup, the library follows the fake pointer to
system(), and the attacker’s command runs. No shellcode is needed, because the library’s own teardown does the work. - The result: A file named
PWNED.txtappears in the data directory. The command ran aswww-data, the user that owns every file on the instance.
PWNED.txt as www-data.A Share Link and a Thumbnail
From the outside, the attack looks like this.
An attacker uploads vacation.heic to a Nextcloud instance. It looks like an ordinary 30 MB iPhone photo. They create a public share link and send it to someone, or post it somewhere.
The recipient clicks. They’re not logged in, and they don’t need to be. Nextcloud’s share page loads and, to render it, requests a thumbnail of the shared file. The browser asks and Nextcloud generates. That single request starts a four-layer trust cascade, each layer handing the file down and trusting the one below to handle it safely:
hvcC and passes the HEVC data through untouched. Only libde265 reads the bitstream’s own dimensions, and those are the ones it uses to size and fill the buffer.OC\Preview\HEIC calls Imagick::readImage(). ImageMagick sees HEIC and passes it to libheif. libheif loads its HEVC plugin, which is backed by libde265, the C++ decoder that does the actual work here.
That preview feature is the attack surface. It’s the most public vector into Nextcloud, reachable through a share link with no login, and an attacker can turn it into a zero-interaction compromise of the server. Wherever an instance generates HEIC previews, a crafted file makes the preview routine run the attacker’s command. Nobody on the server side has to do anything. Generating the thumbnail is the trigger.
And all of it rides on Alpine. The official Nextcloud Docker images are built on the Alpine Linux distribution, and it’s Alpine’s packages that ship the HEIC-capable ImageMagick, libheif, and libde265, already linked and loaded in the image. The decode chain is present out of the box, and the preview feature is simply what reaches it.
We tested two fpm-alpine tags directly, nextcloud:34.0.4.1-fpm-alpine and nextcloud:35.0.1-fpm-alpine. Both ship Alpine’s libde265-1.0.18-r0 and libheif-1.23.4-r0. These are the official Nextcloud Docker images, but they are community-maintained, and the Docker Hub page states Nextcloud GmbH doesn’t support them. Nextcloud’s own All-in-One (AIO) image, which Nextcloud GmbH does maintain, is a separate Alpine build and carried even older versions (libde265-1.0.15-r0, libheif-1.19.5-r0). Every Alpine stable from 3.21 to 3.24 shipped vulnerable libde265 with no backport, though the upstream fix had existed since May 2026.
So the vulnerable decoder was already there: linked, loaded, and one preview request away from any crafted file. The only thing left was to understand what that bug actually did.
The Bug Everyone Called a Crash
CVE-2026-49346 is a known bug in libde265, and it comes with a label: a heap overflow that crashes the decoder, a denial-of-service and nothing more. That label is wrong, and the reason is what the “crash” is actually made of.
The bug lives in de265_image_get_buffer(), the function that reserves memory for a decoded frame. To size the buffer it multiplies the frame’s height by its stride (the bytes in one row) in a signed 32-bit integer. For a normal photo that product is small and correct. For a frame declared 65,528 wide by 32,776 tall at 16-bit depth, it isn’t:
The allocator is asked for about 1 MB, sees nothing wrong, and hands it over. Then the decoder fills it. The code that writes the pixels uses full-width size_t math, so it writes the real frame, tens of megabytes, into the 1 MB buffer it was given. Everything past that first megabyte lands in memory the decoder never reserved. That is the out-of-bounds write, and that is the whole of CVE-2026-49346.
Run it as-is and the process dies, which is exactly where the advisory stops. But a write that runs off the end of a buffer has two properties nobody measured: what it writes, and where it lands. Control those two things, and a crash stops being a crash.
Writing Chosen Bytes to Chosen Places
A buffer overflow is dangerous when the attacker controls two things: the bytes written, and where they land. This one hands over both, because of the file format itself.
The bytes come from PCM. HEVC offers a lossless coding mode, pulse-code modulation, and the attacker chooses it by encoding the crafted frame that way. Where a normal decode rebuilds each pixel through prediction, filtering, and entropy decoding, PCM skips all of it and copies sample values straight from the bitstream into the buffer, one for one. Whatever the attacker writes into the file is exactly what lands in memory, so every overflow byte is theirs.
The location comes from geometry. The decoder fills the buffer in a fixed, known order (row by row, a set number of bytes per row), so the attacker knows which byte in the file maps to which spot in memory, and how far past the undersized buffer it lands. Choosing a pixel is choosing an address.
A normal image overflow is like spilling paint: it runs off the canvas, but you don’t pick the color or where it falls. PCM turns the spill into a printer that lays down chosen bytes at chosen offsets.
The geometry that allows this is tightly constrained, though. The dimensions 65,528 by 32,776, 16-bit monochrome, coding-tree-block size 32, are the one shape that satisfies three requirements at once:
- wrap to a small positive size: a negative size would make the allocator refuse the request instead of under-serving it.
- 32×32 PCM units: the largest libde265 1.0.18 accepts.
- ~4 MB per row of blocks: enough reach to hit the structures the exploit later aims for.
The result is a write primitive: chosen values from PCM, chosen offsets from geometry, reaching tens of megabytes past the buffer. The crash is now a tool the attacker can aim.
But none of it runs if the file is turned away at the door, and an image this size should be. Two checks stand in the way.
Bypassing Two Safety Checks
An image declaring 65,528 by 32,776 pixels should never reach the vulnerable code. Two checks are meant to stop it:
- A pre-decode size limit in libheif, which rejects any image whose pixel count exceeds a set maximum (2^30 by default).
- A post-decode output cap, a limit on the size of the image libheif will return.
Neither check is broken. Each one is sidestepped because of where it looks.
Hiding the real size
libheif reads its size check from the hvcC box, a small metadata record describing the image. The file puts legal dimensions there, 64 by 64, so the check passes. The real geometry lives in the SPS inside the HEVC bitstream, which libde265 reads directly: it adopts 65,528 by 32,776 and decodes at that size. The limit was measuring the wrong number all along.
(libheif 1.23.5 closed this by scanning every in-stream SPS before decode. The images we tested shipped 1.23.4.)
Switching the output off
Every frame is marked pic_output_flag=0, which means “decode this, but don’t return it.” libde265 obliges: it allocates the buffer, runs the decode, triggers the overflow, then discards the frame. Nothing is handed back, so the output cap has nothing to measure.
The discard helps the attacker twice over. With no frame returned, libheif reports failure, ImageMagick gives up, and that failure starts the decoder teardown, which is where the planted bytes fire. But first the overflow has to land on something worth corrupting, and in the process where Nextcloud runs, that’s the hard part.
Aiming the Overflow
A controlled write still isn’t code execution. The overflow runs off the end of the undersized buffer and corrupts whatever memory happens to sit right after it. To matter, that neighbor has to be something the program will later trust and act on. On a simple command-line decoder, a useful target already sits there by luck of the layout. Inside the PHP-FPM worker where Nextcloud runs, it doesn’t: the objects worth corrupting live in a different part of memory, out of the overflow’s reach.
So the real work is arranging for a useful target to be sitting in the overflow’s path at the moment it fires.
That’s harder than it sounds, because the attacker can’t choose memory addresses. The allocator decides where everything goes, and on a live server those locations are randomized. What the attacker can lean on is the one thing the allocator does predictably: it hands out memory roughly in the order it’s asked for, so things allocated back-to-back tend to land next to each other.
That ordering is the lever, and the HEIC file pulls it. A single HEIC can hold several frames, and decoding them triggers allocations in an order the file controls. The crafted file is built as a sequence:
- Frame 1: build, then seed. Frame 1 is a harmless image. Decoding it makes the decoder carve out the large arena that holds the undersized buffer. Then, still before any other frame, the file feeds in the spray: a burst of extra decoder records (SPS structures). Because the arena already exists, these records are allocated right after it, in exactly the memory the overflow will later run into. They are the target: one of these sprayed records is what frame 3’s out-of-bounds write overwrites.
- Frame 2: settle. A second short, harmless image. It nudges the decoder to finish frame 1 and lets the layout settle into place.
- Frame 3: fire. The weapon. It triggers the undersized allocation and the PCM overflow, which floods upward out of the buffer and overwrites one of the sprayed records waiting in its path.
The attacker never controls where the victim’s memory lives. They control the order things are allocated inside the decoder, and that’s enough to seat a chosen target exactly where the overflow will hit it.
Hijacking the Cleanup
The sprayed record the overflow overwrites is a C++ smart pointer, specifically a std::shared_ptr control block: the small bookkeeping object that tracks how many owners a decoder structure has. It holds two things that matter: a reference count, and a pointer to the function that runs when that count hits zero and the object is destroyed.
The overflow replaces it with a counterfeit, assembled entirely from pieces already in the process:
- a fake function pointer, aimed at an instruction sequence already present in libheif instead of injected code
- a reference count set so the object stays “alive” until cleanup releases its last owner
- a command string, the shell command to run, written into fields the decoder never reads again.
No shellcode is introduced. The trick is to point the destructor at a short run of instructions that already exists in the loaded library, a technique called COOP (counterfeit object-oriented programming). The block below is disassembled straight from the libheif shared library shipped in nextcloud:34.0.4.1-fpm-alpine. It is the exact gadget the exploit reuses, at offset libheif + 0x14cf68:
ldr x1, [x0, #0x60] ; x0 = the fake object
ldr w2, [x1]
cmp w2, #4 ; a loose sanity check the fake passes
b.le skip
ldr x0, [x0, #0x68] ; x0 = the command string
ldr x1, [x1, #0x80] ; x1 = system() in musl libc
blr x1 ; system(command)
Stripped down, it does one thing: load the command string, load the address of system(), and call it. The fake object supplies all three values.
Now the trigger. The oversized frame was never returned, so ImageMagick fails and libheif tears the decoder down. Teardown walks its records and releases each one. When it reaches the corrupted control block, the reference count drops to zero and the destructor fires. That destructor is the attacker’s fake pointer.
The library’s own cleanup follows the counterfeit pointer straight into system(). The failed preview is what makes the command run. Teardown is the trigger.
system(), so that ordinary release path runs the attacker’s command.Firing Under ASLR
ASLR randomizes the two addresses the payload depends on: the base of libheif, through which the gadget and system() are reached, and the heap location of the sprayed control block. Neither is fixed from run to run, so the chain has to recover them under ASLR rather than assume them. Two things make that possible.
The leak. Earlier, the weapon frames carried pic_output_flag=0, so the oversized frame was decoded but never returned. A leak frame flips that flag to 1: the frame is decoded and handed back as the thumbnail.
The copy is the same size mismatch, run in reverse. The buffer is undersized by the wrap, but the decoder still works in terms of the full, oversized geometry. To build each output pixel, it reads source samples at positions computed from that large geometry. Those positions fall past the end of the small buffer, into whatever memory sits next to it. The decoder copies those out-of-bounds bytes into the output image, treating them as ordinary pixel values.
Set that frame to be returned, and the neighboring process memory comes back inside the thumbnail. Reading the pixels back out discloses the randomized libheif base and heap addresses while ASLR is on. Those are the values the real payload is built around. Without this step, there’s nothing to aim at.
The spray. The write itself is exact: known bytes, a known distance past the buffer. What isn’t exact is the layout around it. ASLR and the allocator decide where the buffer and the target objects land relative to each other, and that differs every run. The spray closes that gap. Rather than hope a single target happens to fall in the write’s path, the file fills that path with many copies of the target, so any layout that seats the spray above the buffer puts one squarely in reach. Reloading the share link re-rolls the layout and rebuilds the spray. A few reloads are enough to land it where the write will hit, and the chain fires. In the recording, that’s the handful of refreshes before PWNED.txt appears.
The two containers mirror that division. The attacker’s container runs the same image as the target, so its libraries are identical. It’s where the file is built and calibrated. The victim’s container is a separate Nextcloud instance with ASLR on, reachable only through the share link, where the file is planted and fired.
Delivering the Exploit
Everything in the last several sections (the wrap, the controlled write, the two bypasses, the heap grooming, the fake smart pointer, the ASLR leak) is baked into a single file. All of that complexity is a one-time cost for the attacker, paid when the file is built. Using it is trivial.
From the attacker’s side, the whole operation is three steps:
- Upload one file:
vacation.heic, a plausible 30 MB photo. It carries the entire chain: the wrapping SPS, the framing frames, the SPS spray, and the PCM weapon frame. - Create a public share link. No password.
- Open the link, or send it to someone.
When the link is opened, Nextcloud requests the preview, and that single decode runs the chain to completion: frames in order, spray settles, overflow lands, teardown calls system(). A few reloads seat the spray, and the command fires.
The result is a file sitting in the instance’s data directory:
$ curl -u admin:password \
"http://localhost:8885/remote.php/dav/files/admin/PWNED.txt"
RCE-PWNED-BY-HEIC
The command ran inside the PHP-FPM worker as www-data (uid 82), the user that owns every file on the instance. It also ran occ files:scan, so the planted file appears in the web UI immediately, with no admin action.
And because the share link is public, the attacker doesn’t need a victim at all: they can open the preview themselves. Against any instance running the flawed image, that makes this a zero-click remote code execution chain. The attacker drives it from upload to command execution, with nobody else in the loop.
What the Attacker Gets
This isn’t a container escape. The command runs as the PHP-FPM user, not as root on the host. But that user is the Nextcloud instance:
- Every file.
www-datacan read and write the entire data directory: every user’s files, every share, every version. - Admin control through
occ. Nextcloud’s command-line admin tool runs as the same user. From it the attacker can create and delete users, reset passwords, enable or disable apps, flip maintenance mode, and rewrite system configuration. - Enough command room. The planted command can run up to 488 bytes, enough for a reverse shell, an exfiltration one-liner, or a loader that pulls down a larger payload.
From a single public share link, the attacker goes from zero access to full control of the application and everything it stores.
And the reach is wide. The affected fpm-alpine tags were current releases at the time of research. They are the official Nextcloud Docker images, community-maintained and unsupported by Nextcloud GmbH. Nextcloud’s own AIO image, which Nextcloud GmbH does maintain, shipped vulnerable library versions too. Any instance built on these images and generating HEIC previews was exposed.
The Fix
We reported this to the Nextcloud security team, and the official Docker images have since been fixed. The current fpm-alpine images (Nextcloud 32–35) no longer install imagemagick-heic, so the decode path is gone entirely. Alpine 3.24 now ships patched libraries, libde265-1.1.3-r0 and libheif-1.23.7-r0, and either one blocks this chain on its own. We confirmed both by pulling and inspecting the published images. The AIO image has moved to Alpine 3.24 as well.
The Nextcloud team confirmed the fix in their reply to our report:

One gap remains. The advisory, GHSA-vv8h-932h-7r86, still lists “Patched versions: None,” even though libde265 1.1.0 records the CVE as fixed. Its CVSS score of 7.1 also undersells what is, in practice, remote code execution.
Timeline
| Date | Event |
|---|---|
| May 26, 2026 | libde265 1.1.0 released, fixing CVE-2026-49346 |
| May 26, 2026 | GHSA-vv8h-932h-7r86 published (severity: crash/DoS) |
| Sep 25, 2026 | libheif 1.23.5 released with in-stream SPS dimension check |
| Oct 15, 2026 | Reported to Nextcloud with full PoC |
| Oct 20, 2026 | imagemagick-heic removed from all fpm-alpine Dockerfiles |
| Oct 23, 2026 | Alpine 3.24 ships libde265 1.1.3-r0 |
| Nov 6, 2026 | Updated fpm-alpine images published |
| Nov 11, 2026 | Fix verified by pulling and inspecting the actual images |
Lessons
A crash is a code-execution bug you haven’t finished reading. CVE-2026-49346 was rated as denial-of-service for months, while a fix existed and containers kept shipping the flaw. Every memory-corruption crash in a parser deserves the same second look, and AI tooling makes it more likely that someone will take it.
Image decoding is an attack surface nobody chose. Nextcloud’s code has no bug: each layer correctly calls the next, and the flaw sits four layers down, in a dependency of a dependency. It took two libraries together to make it work, an integer overflow in libde265 and a missing size check in libheif, and no application-level audit or test would catch that pairing.
Sandbox the parsers. Containing the next decoder bug lasts longer than patching each one as it appears. A preview worker cut off from the data directory and from outbound connections would have turned this exploit back into a harmless crash.
The bigger picture. Nextcloud is one example of a common setup: any product that turns user files into previews runs deep code its developers never chose, rated by severity labels that can understate the risk. Knowing which of those components the outside world can reach, and treating their crash bugs as possible entry points, is becoming basic security hygiene as AI shortens the path from public bug to working exploit.