[io] pcl::io::raw_open opens files in text mode on Windows, so raw_read alters binary data
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- cpp
调研方向
从 pcl/io/low_level_io.h 开始,在 raw_open 封装 ::_open 的 _WIN32 分支中;将这些重载与 POSIX 的重载进行比较。像 issue 中那样,用一个包含 0D 0A 和 1A 的小型二进制文件复现,并检查 raw_read 的字节计数。然后测试受影响的调用方:用于 binary_compressed 文件的 PCDReader::read 和 LineRGBD::loadTemplates。完成意味着 Windows 的 raw_read 原样返回文件字节,并且不再在 CRLF 或 0x1A 处截断。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
On Windows, pcl::io::raw_open (pcl/io/low_level_io.h) calls ::_open without _O_BINARY. The CRT default translation mode is text (_O_TEXT, unless the application changes _fmode). As a result, pcl::io::raw_read on that descriptor:
- collapses every CR LF pair into LF, compacting the buffer in place, and returns fewer bytes;
- stops at a 0x1A byte.
POSIX open has no text mode, so the same code reads different bytes on Linux and Windows.
PCL reads binary data through these wrappers: PCDReader::read for binary_compressed files and LineRGBD::loadTemplates. raw_open/raw_read are also public API for user code.
Expected behavior
raw_read returns the file's bytes unchanged, as it does on POSIX.
Current Behavior
A file holds the bytes 0D 0A 00 01 40 00 00 02, and 4 bytes are read from it:
| open flags | _read returns | buffer
| O_RDONLY (what raw_open does) | 3 | 0A 00 01 01
| O_RDONLY \| _O_BINARY | 4 | 0D 0A 00 01
With the bytes 1A 0A 00 00, text mode returns 0.
Consequences:
LineRGBD::loadTemplatesreads each.sqmmtentry withraw_read (ltm_fd, buffer, fsize)and checks only for-1. After the first0D 0Apair, every following byte is shifted by one and the tail holds stale bytes.sqmmt.deserializethen reads corrupted data.PCDReader::readreads the 4-byte compressed size of abinary_compressedfile withraw_readand checks onlynum_read < 0. On Windows the value is used only for the file-size check, because the whole file is mapped. When translation makes the value larger, a valid file is rejected with "Corrupted PCD file. The file is smaller than expected!". For example, a compressed size of0x01000A0D(16 779 789 bytes) is read as0x0101000A, which is 62 973 bytes too large.
To Reproduce
#include <pcl/io/low_level_io.h>
#include <fcntl.h>
#include <cstdio>
#include <fstream>
int main ()
{
const unsigned char bytes[] = {0x0D, 0x0A, 0x00, 0x01};
std::ofstream ("crlf.bin", std::ios::binary).write (reinterpret_cast<const char*> (bytes), sizeof (bytes));
int fd = pcl::io::raw_open ("crlf.bin", O_RDONLY);
unsigned char buf[4] = {};
const auto n = pcl::io::raw_read (fd, buf,
pcl::io::raw_close (fd);
std::printf ("n=%d %02X %02X %02X %02X\n",, buf[1], buf[2], buf[3]);
// Linux: n=4 0D 0A 00 01
// Windows: n=3 0A 00 01 01
}
Your Environment (please complete the following information):
- OS: Windows 11
- Compiler: MSVC (Visual Studio 2026)
- PCL Version: 1.12.1 and current master
Possible Solution
Open in binary mode inside the Windows wrappers. O_BINARY does not exist on POSIX, so callers cannot pass it portably.
#ifdef _WIN32
# include <fcntl.h> // _O_BINARY
...
inline int raw_open(const char * pathname, int flags, int mode)
{
return ::_open(pathname, flags | _O_BINARY, mode);
}
inline int raw_open(const char * pathname, int flags)
{
return ::_open(pathname, flags | _O_BINARY);
}
- 主要语言
- C++
- 星标
- 11.2k
- 派生
- 4.7k
- 平均合并
- 6 天 13 小时
- 30 天内合并 PR
- 10
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PointCloudLibrary/pcl 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 67/100
PointCloudLibrary/pcl#6509 · 1 条评论 ·
维护者通常 3 天内回复
-
kind: bug status: triage
难度 4/5 3-5 天 新手友好度 48/100
PointCloudLibrary/pcl#6537 ·
维护者通常 3 天内回复
-
[cmake] QHULL/FLANN dll missing when linking single module可能已有人在做 @SIDDARTHAREDDY8 于 5 天前认领。 未关闭kind: bug module: cmake
难度 3/5 半天 新手友好度 50/100
PointCloudLibrary/pcl#6522 · 1 条评论 ·
维护者通常 3 天内回复
-
kind: bug status: triage
难度 4/5 3-5 天 新手友好度 35/100
PointCloudLibrary/pcl#6395 ·
维护者通常 3 天内回复
-
[sample_consensus] Migrated the SSE and AVX implementations of countWithinDistance to RISC-V RVV 1.0未关闭kind: request status: triage
难度 5/5 一周以上 新手友好度 25/100
PointCloudLibrary/pcl#6385 · 1 个 reaction ·
维护者通常 3 天内回复
查看 PointCloudLibrary/pcl 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
nextcloud/passman-android#214 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
feature wsl2
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
2026.11.0 fails to install on Intel macOS: requirements.txt pins cryptography==50.0.2 for Darwin x86_64可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 1/5 1 小时以内 新手友好度 87/100
esphome/esphome#22892 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 77/100
distante/esphome-components#50 · 1 条评论 ·
维护者通常 1 天内回复