[io] LZF image reader wraps compressed_size + header_size, and Bayer debayer wraps width-2
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- computer-vision, security
Direzione di ricerca
Read io/src/lzf_image_io.cpp around LZFImageReader::loadImageBlob and io/src/debayer.cpp around debayerEdgeAware and the matching loops at lines 588 and 726. Start by checking how the file header sizes and minimum Bayer dimensions are validated before allocation or writes; the issue includes an untested patch and a regression test for the compressed size case, but no patch for the Bayer case. Done means both crafted inputs are rejected safely, with regression coverage for each finding.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
We looked for a private security contact for this project (there is no SECURITY.md, GitHub private vulnerability reporting is disabled, and no security email is listed in the README, CONTRIBUTING.md, or the website), so we are reporting these here.
Our code review of PointCloudLibrary/pcl at commit fd39f32af932d50e033dba17b29e6d5fa4f64255 (master; that was also the current HEAD when we read it) found two memory-safety bugs in the LZF image readers. This is source review only; nothing was run or compiled.
- io/src/lzf_image_io.cpp, LZFImageReader::loadImageBlob: line 429 checks compressed_size + header_size against the mapped file size. compressed_size is a uint32 taken from the file (lines 426-427) and header_size is 37 (line 48), so the sum is computed in 32 bits and can wrap. When that check passes, line 443 resizes a buffer to compressed_size and line 444 copies that many bytes out of the mapping. A crafted .pclzf can therefore cause a very large allocation and a copy from a short mapping. This is reachable through pcl_pclzf2pcd, ImageGrabber in pclzf mode, and the public LZF*ImageReader::read.
An untested fix is included below as pcl-301-f2.patch (apply with git apply, not git am). It compares the sum in 64 bits and adds a regression test in test/io/test_io.cpp. It has not been compiled or run; it passes git apply --check on the commit above.
This is distinct from merged #6504, which already does the width × height uncompressed-size comparison in 64 bits (io/include/pcl/io/impl/lzf_image_io.hpp line 447). That change does not cover the compressed_size + header_size addition at line 429, which is still in 32 bits on this commit.
- io/src/debayer.cpp, debayerEdgeAware: lines 439-465 write the first pixels unconditionally, including past rgb_buffer[rgb_line_step + 5]. Line 471 (and the same pattern at lines 588 and 726; the outer loop at line 546 is height - 2) is
for (unsigned xIdx = 2; xIdx < width - 2; ...). When width is below 2, the bound wraps. The only size check on this path is uncompressed_size == width × height (lzf_image_io.hpp line 447); line 463 allocates width × height × 3 bytes and line 465 calls the debayer. A small Bayer .pclzf that passes that check can therefore write past a small RGB buffer and then loop for a very large count. We do not have a patch for this finding; none was prepared. In words, the reader should refuse images smaller than the minimum this routine assumes, before it writes anything.
Merged #6504 mentioned the Bayer reader only for the large-dimension width × height wrap, which that change already closed. The width-2 loop bound is a separate leftover.
pcl-301-f2.patch (untested)
diff --git a/io/src/lzf_image_io.cpp b/io/src/lzf_image_io.cpp
index 5c01cfb..803abae 100644
--- a/io/src/lzf_image_io.cpp
+++ b/io/src/lzf_image_io.cpp
@@ -426,7 +426,9 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename,
std::uint32_t compressed_size;
memcpy (&compressed_size, &map[29], sizeof (std::uint32_t));
- if (compressed_size + header_size != data_size)
+ // Compare in 64 bits: compressed_size comes from the file, and adding the header size to it in
+ // 32-bit unsigned arithmetic wraps, so a tiny file can claim a ~4 GB payload and pass this check
+ if (static_cast<std::uint64_t> (compressed_size) + header_size != static_cast<std::uint64_t> (data_size))
{
PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] Number of bytes to decompress written in file (%u) differs from what it should be (%u)!\n", compressed_size, data_size - header_size);
#ifdef _WIN32
diff --git a/test/io/test_io.cpp b/test/io/test_io.cpp
index 9632bbf..4478c78 100644
--- a/test/io/test_io.cpp
+++ b/test/io/test_io.cpp
@@ -1849,6 +1913,29 @@ TEST (PCL, LZFImageWrappedDimensions)
remove ("test_lzf_bayer.pclzf");
}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+TEST (PCL, LZFImageWrappedCompressedSize)
+{
+ // compressed_size is read from the file and was added to the 37-byte header size in 32-bit
+ // unsigned arithmetic, so this 36-byte file claiming 0xFFFFFFFF compressed bytes passed the size
+ // check and the reader went on to copy ~4 GB out of a one-page mapping.
+ char header[36] = {};
+ const std::uint32_t width = 1, height = 1, compressed_size = 0xFFFFFFFF;
+ memcpy (&header[0], "PCLZF", 5);
+ memcpy (&header[5], &width, sizeof (width));
+ memcpy (&header[9], &height, sizeof (height));
+ memcpy (&header[13], "depth16", 7);
+ memcpy (&header[29], &compressed_size, sizeof (compressed_size));
+ std::ofstream fs ("wrapped_compressed_size.pclzf", std::ios::binary);
+ fs.write (header, sizeof (header));
+ fs.close ();
+
+ PointCloud<PointXYZ> depth_cloud;
+ pcl::io::LZFDepth16ImageReader reader;
+ EXPECT_FALSE (reader.read ("wrapped_compressed_size.pclzf", depth_cloud));
+ remove ("wrapped_compressed_size.pclzf");
+}
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, Locale)
{
Credit: Ugur Celik (ucsurf), @ucsurf
— Ugur Celik (ucsurf) · https://uc.surf
We find and report security issues in open source before attackers do. If our work helped you, a small contribution keeps it going and makes the internet a little safer for everyone:
https://buymeacoffee.com/ucsurf
- Lingua principale
- C++
- Stelle
- 11.2k
- Fork
- 4.7k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PointCloudLibrary/pcl
-
kind: bug status: triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
PointCloudLibrary/pcl#6543 ·
-
[io] pcl::io::raw_open opens files in text mode on Windows, so raw_read alters binary dataForse già presa @Aditya-stack-droid l’ha presa 3 giorni fa. Apertakind: bug status: triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
PointCloudLibrary/pcl#6536 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
PointCloudLibrary/pcl#6509 · 1 commento ·
-
kind: bug status: triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
PointCloudLibrary/pcl#6544 ·
-
kind: bug status: triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
PointCloudLibrary/pcl#6537 ·
Tutte le issue di PointCloudLibrary/pcl
Issue simili
-
Invalid-MissingHash/Commit/NotAC
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
azerothcore/azerothcore-wotlk#28636 ·
I maintainer di solito rispondono entro 1 giorno
-
(S1 - Need confirmation)
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CleverRaven/Cataclysm-DDA#89829 ·
I maintainer di solito rispondono entro 1 giorno
-
comp-documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ClickHouse/ClickHouse#136277 ·
I maintainer di solito rispondono entro 1 giorno
-
Flow Needs: Triage :mag:
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
react/react-native#60447 ·
I maintainer di solito rispondono entro 1 giorno
-
RecompLauncher supportAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno