{"id":12920,"date":"2026-05-16T10:03:42","date_gmt":"2026-05-16T10:03:42","guid":{"rendered":"https:\/\/serisec.com\/index.php\/2026\/05\/16\/malicious-jpeg-images-could-trigger-php-memory-safety-vulnerabilities\/"},"modified":"2026-05-16T10:03:42","modified_gmt":"2026-05-16T10:03:42","slug":"malicious-jpeg-images-could-trigger-php-memory-safety-vulnerabilities","status":"publish","type":"post","link":"https:\/\/serisec.com\/index.php\/2026\/05\/16\/malicious-jpeg-images-could-trigger-php-memory-safety-vulnerabilities\/","title":{"rendered":"Malicious JPEG Images Could Trigger PHP Memory Safety Vulnerabilities"},"content":{"rendered":"<p>    Malicious JPEG Images Could Trigger PHP Memory Safety Vulnerabilities<br \/>\n \t<BR><br \/>\n<BR><\/BR><br \/>\n    <!-- no image --><br \/>\n \t<BR><br \/>\n<BR><\/BR><\/p>\n<div>\n<p>Two critical memory-safety vulnerabilities in PHP\u2019s image-processing functions could allow attackers to leak<a href=\"https:\/\/cybersecuritynews.com\/php-extract-function-vulnerability\/\" target=\"_blank\" rel=\"noreferrer noopener\"> sensitive heap memory<\/a> or to execute denial-of-service attacks via specially crafted JPEG files. <\/p>\n<p>The flaws, discovered in PHP\u2019s ext\/standard extension by<a href=\"https:\/\/swarm.ptsecurity.com\/hack-the-elephant-one-bite-at-a-time-jpeg-related-memory-safety-bugs-in-php\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> Positive Technologies researcher Nikita Sveshnikov<\/a>, affect the widely-used getimagesize and iptcembed functions that process JPEG metadata and IPTC data.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-php-memory-safety-vulnerabilities\"><strong>PHP Memory Safety Vulnerabilities<\/strong><\/h2>\n<p>The first vulnerability, tracked as <a href=\"https:\/\/nvd.nist.gov\/vuln\/detail\/CVE-2025-14177\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">CVE-2025-14177<\/a> with a CVSS score of 6.3, enables information disclosure when PHP\u2019s getimagesize function processes JPEG APP segments in multi-chunk reading mode. <\/p>\n<p>Affected versions include PHP 8.1.* before 8.1.34, 8.2.* before 8.2.30, 8.3.* before 8.3.29, 8.4.* before 8.4.16, and 8.5.* before 8.5.1.<\/p>\n<p>The vulnerability stems from a bug in the php_read_stream_all_chunks function that incorrectly concatenates data chunks when reading JPEG application segments. When processing APP segments containing metadata such as EXIF or IPTC data, the function allocates uninitialized heap memory. <\/p>\n<p>However, it fails to increment the buffer pointer after each read. This causes subsequent chunks to overwrite the beginning of the buffer, leaving the tail bytes uninitialized and exposing fragments of process memory.<\/p>\n<p>Attackers can exploit this flaw by<a href=\"https:\/\/cybersecuritynews.com\/hackers-use-weaponized-jpeg-file\/\" target=\"_blank\" rel=\"noreferrer noopener\"> crafting JPEG files with large APP1 segments <\/a>designed to be read across multiple chunks, particularly when the default chunk size of 8,192 bytes is known. <\/p>\n<p>When applications process these malicious images through php:\/\/filter or other multi-chunk reading mechanisms, uninitialized heap data containing potentially sensitive information gets copied into the $info[\u2018APPn\u2019] array returned by getimagesize.<\/p>\n<p>The attack surface is particularly concerning for public-facing upload endpoints, content management systems that generate thumbnails, webmail services, and image CDNs that perform server-side analysis of user-uploaded images. <\/p>\n<p>Remote attackers can leverage the vulnerability if they can cause a vulnerable PHP process to call getimagesize on attacker-controlled data.<\/p>\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"400\" src=\"https:\/\/i0.wp.com\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-1024x400.webp?resize=1024%2C400&#038;ssl=1\" alt=\"Chunk read bug visualization (Source: PTSecurity)\" class=\"wp-image-150170\" srcset=\"https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-1024x400.webp 1024w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-300x117.webp 300w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-768x300.webp 768w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-1536x601.webp 1536w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-1074x420.webp 1074w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-150x59.webp 150w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-696x272.webp 696w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3-1068x418.webp 1068w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/3428bc88-image-3.webp 1560w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><figcaption class=\"wp-element-caption\">Chunk read bug visualization (Source: PTSecurity)<\/figcaption><\/figure>\n<h2 class=\"wp-block-heading\" id=\"h-heap-buffer-overflow-in-iptcembed\"><strong>Heap Buffer Overflow in iptcembed<\/strong><\/h2>\n<p>The second vulnerability affects the iptcembed function, which embeds binary IPTC data into JPEG images. <\/p>\n<p>This classic heap buffer overflow occurs due to a \u201cmeasure once, read forever\u201d flaw: the function allocates an output buffer based on a single fstat result. It continues reading data until EOF without capacity checks.<\/p>\n<p>The root cause lies in how iptcembed handles non-standard file types such as FIFOs, pipes, and sockets. For these file types, the st_size field returned by fstat is 0, causing the function to allocate an undersized buffer. <\/p>\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"358\" src=\"https:\/\/i0.wp.com\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-1024x358.webp?resize=1024%2C358&#038;ssl=1\" alt=\"iptcembed buffer allocation (Source: PTSecurity)\" class=\"wp-image-150171\" srcset=\"https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-1024x358.webp 1024w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-300x105.webp 300w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-768x269.webp 768w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-1536x538.webp 1536w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-1200x420.webp 1200w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-150x53.webp 150w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-696x244.webp 696w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1-1068x374.webp 1068w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/f5acd532-image-1.webp 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><figcaption class=\"wp-element-caption\">iptcembed buffer allocation (Source: PTSecurity)<\/figcaption><\/figure>\n<p>The code then copies input data into the spoolbuf buffer without verifying available space, resulting in out-of-bounds writes when the stream contains more data than is allocated.<\/p>\n<p>This vulnerability also introduces a time-of-check to time-of-use (TOCTOU) race condition in which regular files can grow in size after fstat but before the read operation completes. <\/p>\n<p>Attackers can exploit this by feeding large amounts of data through specially crafted JPEG structures that force the parser into \u201cread everything until EOF\u201d mode, triggering heap corruption.<\/p>\n<p>Both vulnerabilities exploit weaknesses in PHP\u2019s Zend Engine memory management, specifically in functions handling JPEG marker processing. <\/p>\n<p>The getimagesize flaw affects the php_read_APP function, which processes application-specific segments (APP0-APP15) that contain metadata such as EXIF coordinates, IPTC authorship information, and XMP data.<\/p>\n<p>For CVE-2025-14177, the vulnerable code path begins when getimagesize allocates memory using emalloc, which returns uninitialized memory pointers. <\/p>\n<p>If multi-chunk reading occurs, the php_stream_read macro writes to the same destination address without applying offsets for already-read bytes, causing the final chunk to overwrite the buffer\u2019s beginning while leaving the tail section untouched.<\/p>\n<p>The iptcembed buffer overflow manifests when processing M_APP13 or M_SOS (start of scan) markers, where the parser switches to php_iptc_read_remaining mode and copies data until EOF. <\/p>\n<p>The vulnerable php_iptc_get1 function advances the write pointer (poi) for every byte without checking against the allocated spoolbuf_end boundary.<\/p>\n<p>Researchers demonstrated both vulnerabilities through practical exploits. For the memory disclosure flaw, they created a minimal JPEG with a large APP1 segment designed to be read across multiple 8,192-byte chunks, performed heap spraying with marker strings to fill memory, then read the file through php:\/\/filter to force multi-chunk processing. <\/p>\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"937\" src=\"https:\/\/i0.wp.com\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-1024x937.webp?resize=1024%2C937&#038;ssl=1\" alt=\"iptcembed overflow diagram (Source: PTSecurity)\" class=\"wp-image-150172\" srcset=\"https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-1024x937.webp 1024w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-300x274.webp 300w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-768x702.webp 768w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-459x420.webp 459w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-150x137.webp 150w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-696x637.webp 696w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2-1068x977.webp 1068w, https:\/\/cybersecuritynews.com\/wp-content\/uploads\/2026\/05\/c2f36e51-image-2.webp 1230w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><figcaption class=\"wp-element-caption\">iptcembed overflow diagram (Source: PTSecurity)<\/figcaption><\/figure>\n<p>The proof-of-concept successfully leaked the marker string \u201cLEAK-MARKER-123!\u201d from uninitialized heap memory.<\/p>\n<p>The iptcembed overflow was demonstrated using a two-terminal setup with named pipes (FIFO), where one terminal ran PHP reading from the pipe while another fed a<a href=\"https:\/\/cybersecuritynews.com\/malicious-payload-uncovered-in-jpeg-image-using-steganography\/\" target=\"_blank\" rel=\"noreferrer noopener\"> crafted JPEG structure followed <\/a>by 8MB of data. <\/p>\n<p>Since FIFOs report st_size as zero, the allocated buffer was too small to contain the incoming stream, triggering AddressSanitizer to detect the heap buffer overflow.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-patches-and-remediation\"><strong>Patches and Remediation<\/strong><\/h2>\n<p>PHP developers addressed CVE-2025-14177 by modifying php_read_stream_all_chunks to advance the buffer pointer after each read operation (buffer += read_now), ensuring sequential chunk appending. <\/p>\n<p>The fix was accompanied by a regression test ext\/standard\/tests\/image\/gh20584.phpt to prevent future occurrences.<\/p>\n<p>For the IPTC embed vulnerability, developers added a spoolbuf_end parameter to the php_iptc_get1 and php_iptc_put1 functions to enforce bounds checking. The updated code now safely returns EOF when the buffer is full, rather than writing out of bounds.<\/p>\n<p>Organizations should immediately inventory all hosts and containers running PHP, prioritizing public-facing upload endpoints, CMS thumbnailers, webmail systems, and image CDNs. Updates should be applied to the latest patched versions: 8.1.34, 8.2.30, 8.3.29, 8.4.16, or 8.5.1 and above.<\/p>\n<p class=\"has-text-align-center has-background\" style=\"background:linear-gradient(180deg,rgb(238,238,238) 91%,rgb(169,184,195) 100%)\"><strong>Follow us on\u00a0<a href=\"https:\/\/news.google.com\/publications\/CAAqMggKIixDQklTR3dnTWFoY0tGV041WW1WeWMyVmpkWEpwZEhsdVpYZHpMbU52YlNnQVAB?hl=en-IN&amp;gl=IN&amp;ceid=IN:en\" target=\"_blank\" rel=\"noreferrer noopener\">Google News<\/a>,\u00a0<a href=\"https:\/\/www.linkedin.com\/company\/cybersecurity-news\/\" target=\"_blank\" rel=\"noreferrer noopener\">LinkedIn<\/a>,\u00a0and\u00a0<a href=\"https:\/\/x.com\/cyber_press_org\" target=\"_blank\" rel=\"noreferrer noopener\">X<\/a>\u00a0to Get More Instant Updates.<\/strong><\/p>\n<p>The post <a href=\"https:\/\/cybersecuritynews.com\/malicious-jpeg-images-php-memory-safety-vulnerabilities\/\">Malicious JPEG Images Could Trigger PHP Memory Safety Vulnerabilities<\/a> appeared first on <a href=\"https:\/\/cybersecuritynews.com\/\">Cyber Security News<\/a>.<\/p>\n<\/div>\n<p> \t<BR><br \/>\n <BR><\/BR><br \/>\n    Dhivya<br \/>\n \t<BR><br \/>\n<BR><\/BR><br \/>\n<a href=\"https:\/\/cybersecuritynews.com\/malicious-jpeg-images-php-memory-safety-vulnerabilities\/\">Go to cyber-security-news<\/a><br \/>\n \t<BR><br \/>\n <BR><\/BR><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Malicious JPEG Images Could Trigger PHP Memory Safety Vulnerabilities Two critical memory-safety vulnerabilities in PHP\u2019s image-processing functions could allow attackers to leak sensitive heap memory or to execute denial-of-service attacks via specially crafted JPEG files. The flaws, discovered in PHP\u2019s ext\/standard extension by Positive Technologies researcher Nikita Sveshnikov, affect the widely-used getimagesize and iptcembed functions [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129,63,131],"tags":[130],"class_list":["post-12920","post","type-post","status-publish","format-standard","hentry","category-cyber-security","category-cyber-security-news","category-vulnerability","tag-cyber-security-news"],"_links":{"self":[{"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/posts\/12920"}],"collection":[{"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/comments?post=12920"}],"version-history":[{"count":0,"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/posts\/12920\/revisions"}],"wp:attachment":[{"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/media?parent=12920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/categories?post=12920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/serisec.com\/index.php\/wp-json\/wp\/v2\/tags?post=12920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}