
Cloud Vulnerability DB
A community-led vulnerabilities database
league\csv CharsetConverter::filter() can accumulate an unbounded amount of input in memory and repeatedly revalidate the growing buffer when processing streams containing invalid multibyte sequences, resulting in quadratic CPU consumption and excessive memory usage.
CharsetConverter::filter() validates the accumulated input with mb_check_encoding(). If validation fails and the stream is not closing, it stores the whole input in $this->buffer and returns PSFS_FEED_ME. The intent is to wait for the rest of a multibyte character split across two chunks. But a byte sequence that is invalid anywhere in the buffer, not just an incomplete character at its end, never becomes valid however much more data arrives. So one invalid byte near the start of a file makes the filter keep the entire rest of the stream in memory, and re-validate the growing buffer on every 8 KiB chunk, until EOF. No record is returned before that. CPU is O(n^2) and memory is a multiple of the file size.
Offended source code: https://github.com/thephpleague/csv/blob/master/src/CharsetConverter.php#L267-L273
Requires that you install league/csv and a huge file with invalid encoded characters is processed using the CharserConverter class as a stream filter.
CharserConverter as a stream filter implementing class.<?php
use League\Csv\CharsetConverter;
use League\Csv\Reader;
$path = tempnam(sys_get_temp_dir(), 'csv');
$h = fopen($path, 'wb');
fwrite($h, "\xFF,x\n"); // one byte that is invalid in UTF-8
for ($i = 0; $i < 16_000; ++$i) { // ~14.4 MB
fwrite($h, str_repeat('abcdefgh,', 100)."\n");
}
fclose($h);
$reader = Reader::from($path, 'r');
CharsetConverter::addTo($reader, 'UTF-8', 'ISO-8859-1');
$t = hrtime(true);;
foreach ($reader as $record) { break; } // first record only
printf("%.1f s, %.1f MB peak\n", hrtime(true) - $t, memory_get_peak_usage() / 1e6);Type of vulnerability: Denial of Service (DoS) due to uncontrolled resource consumption (CWE-400).
Who is impacted: Applications using the CharsetConverter stream filter from the League\Csv library to process untrusted or malformed input streams.
An attacker able to supply a crafted input stream containing invalid multibyte character sequences can cause the filter to accumulate an ever-growing buffer and repeatedly validate it. This results in quadratic CPU consumption and excessive memory usage, potentially exhausting the application's available resources.
The vulnerability can affect application availability and may cause significant performance degradation or process termination due to memory exhaustion.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."