mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-25 15:47:25 +08:00
Fixed buffer overflow in the OBJ parser.
Improved error reporting on OBJ parser.
This commit is contained in:
parent
b1095adc18
commit
ba9a9b4e7a
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define DIR_SEPARATOR '\\'
|
#define DIR_SEPARATOR '\\'
|
||||||
#else
|
#else
|
||||||
@ -22,7 +24,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
|
|||||||
// Parse the OBJ file.
|
// Parse the OBJ file.
|
||||||
ObjParser::ObjData data;
|
ObjParser::ObjData data;
|
||||||
if (! ObjParser::objparse(path, data)) {
|
if (! ObjParser::objparse(path, data)) {
|
||||||
// die "Failed to parse $file\n" if !-e $path;
|
BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +105,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr)
|
|||||||
stl_get_size(&stl);
|
stl_get_size(&stl);
|
||||||
mesh.repair();
|
mesh.repair();
|
||||||
if (mesh.facets_count() == 0) {
|
if (mesh.facets_count() == 0) {
|
||||||
// die "This OBJ file couldn't be read because it's empty.\n"
|
BOOST_LOG_TRIVIAL(error) << "load_obj: This OBJ file couldn't be read because it's empty. " << path;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
#include <boost/nowide/cstdio.hpp>
|
#include <boost/nowide/cstdio.hpp>
|
||||||
|
|
||||||
#include "objparser.hpp"
|
#include "objparser.hpp"
|
||||||
@ -312,7 +313,7 @@ static bool obj_parseline(const char *line, ObjData &data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
printf("ObjParser: Unknown command: %c\r\n", c1);
|
BOOST_LOG_TRIVIAL(error) << "ObjParser: Unknown command: " << c1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,12 +345,16 @@ bool objparse(const char *path, ObjData &data)
|
|||||||
lastLine = i + 1;
|
lastLine = i + 1;
|
||||||
}
|
}
|
||||||
lenPrev = len - lastLine;
|
lenPrev = len - lastLine;
|
||||||
|
if (lenPrev > 65536) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "ObjParser: Excessive line length";
|
||||||
|
::fclose(pFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
memmove(buf, buf + lastLine, lenPrev);
|
memmove(buf, buf + lastLine, lenPrev);
|
||||||
assert(lenPrev <= 65536);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::bad_alloc&) {
|
catch (std::bad_alloc&) {
|
||||||
printf("Out of memory\r\n");
|
BOOST_LOG_TRIVIAL(error) << "ObjParser: Out of memory";
|
||||||
}
|
}
|
||||||
::fclose(pFile);
|
::fclose(pFile);
|
||||||
|
|
||||||
@ -381,7 +386,8 @@ bool objparse(std::istream &stream, ObjData &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::bad_alloc&) {
|
catch (std::bad_alloc&) {
|
||||||
printf("Out of memory\r\n");
|
BOOST_LOG_TRIVIAL(error) << "ObjParser: Out of memory";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user