Merge branch 'Fix_buffer_overflow' into 'master'

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

See merge request OpenMesh/OpenMesh!340
This commit is contained in:
Jan Möbius
2023-10-26 10:15:21 +00:00
2 changed files with 12 additions and 1 deletions

View File

@@ -33,6 +33,7 @@
<li>OBJ writer: Added param 'texture_file' to the Options class, it specifies the path to the texture file (Thanks to Philipp Auersperg-Castell for the patch)</li> <li>OBJ writer: Added param 'texture_file' to the Options class, it specifies the path to the texture file (Thanks to Philipp Auersperg-Castell for the patch)</li>
<li>OBJ writer: added param 'material_file_extension' to the Options class, it specifies the material file suffix, default is ".mat" as it was before. (Thanks to Philipp Auersperg-Castell for the patch)</li> <li>OBJ writer: added param 'material_file_extension' to the Options class, it specifies the material file suffix, default is ".mat" as it was before. (Thanks to Philipp Auersperg-Castell for the patch)</li>
<li>PLY reader/writer: Support for meshlab texture coordinates and ids in PLY IO (Thanks to Gregoire Grzeczkowicz for the patch)</li> <li>PLY reader/writer: Support for meshlab texture coordinates and ids in PLY IO (Thanks to Gregoire Grzeczkowicz for the patch)</li>
<li>PLY reader/writer: Fixed possible buffer overflow(Thanks to Ondřej Nečas for the bugreport)</li>
</ul> </ul>
<b>Build System</b> <b>Build System</b>

View File

@@ -145,7 +145,17 @@ private:
/// Read unsupported properties in PLY file /// Read unsupported properties in PLY file
void consume_input(std::istream& _in, int _count) const { 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]; mutable unsigned char buff[8];