Fixed possible buffer overflow (Thanks to Ondřej Nečas for the Bugreport)

This commit is contained in:
Jan Möbius
2023-10-26 11:27:28 +02:00
parent aaf3fb292c
commit e0ce1bcddf
2 changed files with 12 additions and 1 deletions

View File

@@ -145,7 +145,17 @@ private:
/// Read unsupported properties in PLY file
void consume_input(std::istream& _in, int _count) const {
_in.read(reinterpret_cast<char*>(&buff[0]), _count);
// Make sure, we do not run over our buffer size
int loops = _count / 8 ;
// Read only our buffer size batches
for ( auto i = 0 ; i < loops; ++i) {
_in.read(reinterpret_cast<char*>(&buff[0]), 8);
}
// Read reminder which is smaller than our buffer size
_in.read(reinterpret_cast<char*>(&buff[0]), _count - 8 * loops );
}
mutable unsigned char buff[8];