Hi Asen,
I have just had a look at your proposed changes and reviewed the code
that it modifies and see the bug, but the change you've made is
comparing a unsigned int against -1, something this is an undefined
comparison and something that compilers should pick up as being a
problem. This suggests that there is an underlying issue with the
wider code - the assumption that length is always greater than 0.
To avoid the comparison of an unsigned and signed I had changed the
code so that comparison is done directly against the length rather
than length minus one.
diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp
b/src/osgPlugins/stl/ReaderWriterSTL.cpp
index 8955614..92aed56 100644
--- a/src/osgPlugins/stl/ReaderWriterSTL.cpp
+++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp
@@ -588,9 +588,11 @@ ReaderWriterSTL::ReaderObject::ReadResult
ReaderWriterSTL::AsciiReaderObject::re
while (fgets(buf, sizeof(buf), fp))
{
- // strip '\n' or '\r\n' and trailing whitespace
- unsigned int len = strlen(buf) - 1;
+ unsigned int len = strlen(buf);
+ if (len==0) continue;
+ // strip '\n' or '\r\n' and trailing whitespace
+ --len;
while (len && (buf[len] == '\n' || buf[len] == '\r' ||
isspace(buf[len])))
{
buf[len--] = '\0';
This fix is now checked in git master.
Could you test this with your dataset.
Robert.
On 14 July 2016 at 10:53, Asen Kurin <[email protected]> wrote:
> I found that some ASCII STL files from our archive causes SEGFAULT or
> SIGBUS while reading in OSG.
> These files ends with "\r\n\0". I dont know which program produce such files.
>
> I found and fixed bug in OSG ASCII STL reading code, and attach a
> source code file. Fix is very simple and short. Fix based on lastest
> git verion from repository.
>
> Short code description: ./src/osgPlugins/stl/ReaderWriterSTL.cpp:585
>
> while (fgets(buf, sizeof(buf), fp))
> {
> // strip '\n' or '\r\n' and trailing whitespace
> unsigned int len = strlen(buf) - 1;
>
> while (len && (buf[len] == '\n' || buf[len] == '\r' ||
> isspace(buf[len])))
> {
> buf[len--] = '\0';
> }
>
> In case of "\r\n\0" in end file, fgets successfully reads empty
> string (one "\0").
> So, fgets (...) is true, strlen(buf) = 0, len unsigned (!!!!!) == -1,
> and isspace(buf[len]) causes SIGBUS/SIGFOULT.
>
> I propose to change the code as follows:
> while (fgets(buf, sizeof(buf), fp))
> {
> // strip '\n' or '\r\n' and trailing whitespace
> unsigned int len = strlen(buf) - 1;
> if (len == -1) {
> continue;
> }
> while (len && (buf[len] == '\n' || buf[len] == '\r' ||
> isspace(buf[len])))
> {
> buf[len--] = '\0';
> }
>
>
> I hope for further development of your wonderful project.
>
>
> Best regards, Arseny Kurin
> cell. +79370029219, mailto:[email protected], skype:asen.kurin
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org