Fixed buffer overflow in the OBJ parser.

Improved error reporting on OBJ parser.
This commit is contained in:
Vojtech Bubnik 2020-12-17 09:52:59 +01:00
parent b1095adc18
commit ba9a9b4e7a
2 changed files with 14 additions and 6 deletions

View file

@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <boost/log/trivial.hpp>
#include <boost/nowide/cstdio.hpp>
#include "objparser.hpp"
@ -312,7 +313,7 @@ static bool obj_parseline(const char *line, ObjData &data)
break;
}
default:
printf("ObjParser: Unknown command: %c\r\n", c1);
BOOST_LOG_TRIVIAL(error) << "ObjParser: Unknown command: " << c1;
break;
}
@ -344,12 +345,16 @@ bool objparse(const char *path, ObjData &data)
lastLine = i + 1;
}
lenPrev = len - lastLine;
if (lenPrev > 65536) {
BOOST_LOG_TRIVIAL(error) << "ObjParser: Excessive line length";
::fclose(pFile);
return false;
}
memmove(buf, buf + lastLine, lenPrev);
assert(lenPrev <= 65536);
}
}
catch (std::bad_alloc&) {
printf("Out of memory\r\n");
BOOST_LOG_TRIVIAL(error) << "ObjParser: Out of memory";
}
::fclose(pFile);
@ -381,7 +386,8 @@ bool objparse(std::istream &stream, ObjData &data)
}
}
catch (std::bad_alloc&) {
printf("Out of memory\r\n");
BOOST_LOG_TRIVIAL(error) << "ObjParser: Out of memory";
return false;
}
return true;