[io] LZF image reader wraps compressed_size + header_size, and Bayer debayer wraps width-2
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- cpp
- Área
- computer-vision, security
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- C++
- Estrellas
- 11.2k
- Forks
- 4.7k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PointCloudLibrary/pcl
-
kind: bug status: triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
PointCloudLibrary/pcl#6543 ·
-
[io] pcl::io::raw_open opens files in text mode on Windows, so raw_read alters binary dataPosiblemente ocupada @Aditya-stack-droid la tomó hace 3 días. Abiertokind: bug status: triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
PointCloudLibrary/pcl#6536 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
PointCloudLibrary/pcl#6509 · 1 comentario ·
-
kind: bug status: triage
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
PointCloudLibrary/pcl#6544 ·
-
kind: bug status: triage
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
PointCloudLibrary/pcl#6537 ·
Todos los issues de PointCloudLibrary/pcl
Issues similares
-
Invalid-MissingHash/Commit/NotAC
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
azerothcore/azerothcore-wotlk#28636 ·
Los mantenedores suelen responder en 1 día
-
(S1 - Need confirmation)
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
CleverRaven/Cataclysm-DDA#89829 ·
Los mantenedores suelen responder en 1 día
-
comp-documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ClickHouse/ClickHouse#136277 ·
Los mantenedores suelen responder en 1 día
-
Flow Needs: Triage :mag:
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
react/react-native#60447 ·
Los mantenedores suelen responder en 1 día
-
RecompLauncher supportAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día