Package: meshlab Version: 2020.09+dfsg1-2 Severity: important Tags: patch Opening an OBJ whose faces use its first vertex, which is nearly every OBJ, aborts MeshLab 2020.09 & meshlabserver. A single triangle is enough:
$ xvfb-run -a meshlabserver -i triangle.obj -o out.ply
meshlabserver: ./vcglib/wrap/io_trimesh/import_obj.h:640: static int
vcg::tri::io::ImporterOBJ<OpenMeshType>::Open(OpenMeshType&, const char*,
Info&) [with OpenMeshType = CMeshO]: Assertion `(numTriangles +numVertices)
== numVerticesPlusFaces+extraTriangles' failed.
Aborted
Seen on Ubuntu 24.04 with 2020.09+dfsg1-2build2, built from the same source
as bookworm's & trixie's
2020.09+dfsg1-2. Ubuntu's report is
https://bugs.launchpad.net/ubuntu/+source/meshlab/+bug/1995736.
The cause is two lines in MeshLab 2020.09's bundled copy of vcglib, which
the 2020.09 vcglib tag doesn't
have. vcglib/wrap/io_trimesh/import_obj.h adds this to GoodObjIndex:
if (index == 0)
return false; // in obj files, indices must start from 1
SplitToken has already taken one from every index before GoodObjIndex runs,
so 0 is the file's vertex 1.
Every face using the first vertex is dropped without an error. The package
builds with CMAKE_BUILD_TYPE=None,
so NDEBUG is unset & the count check at line 640 aborts. vcglib dropped the
check after 2020.09.
2020.12, 2022.02, 2023.12 & 2025.07 don't have it, so 2025.07~dfsg in
unstable is not affected.
The attached patch removes those two lines, & applies to the 2020.09+dfsg1
source with -p1. Removing them
alone would bring back an older fault, which vcglib fixed on devel in
commit c7dfcd9a: GoodObjIndex compares
the zero based index as one based, so an index one past the last vertex
passes & is read past the vertex
vector, & the triangulating path ignores what GoodObjIndex returns. So the
patch also holds the index below
the vertex count & checks that path, as devel does. I tested it by
compiling the importer from the orig
tarball, with the patch & with assertions on. One & two triangle OBJ files,
relative indices & a textured
quad load with all their faces, where the unpatched copy aborts. A face
naming a vertex past the last is
refused. I haven't rebuilt the package.
Since bookworm & trixie can open almost no OBJ file, the fix may suit a
stable update.
This bug was found during the open-source development of zelon88/HRConvert2
and zelon88/HRProprietary.
Thank you,
Justin Grimes
[email protected]
@zelon88 on Github
triangle.obj
Description: application/tgif
--- a/vcglib/wrap/io_trimesh/import_obj.h
+++ b/vcglib/wrap/io_trimesh/import_obj.h
@@ -180,15 +180,16 @@
// Helper functions that checks the range of indexes
// putting them in the correct range if less than zero (as in the obj style)
+ // The index arrives zero based, because SplitToken takes one from the file's: the file's 1 is 0 here, its 0 is -1,
+ // & a relative -1 is -2. A valid index is below maxVal, & the file's 0 names nothing.
static bool GoodObjIndex(int &index, const int maxVal)
{
- if (index > maxVal) return false;
- if (index == 0)
- return false; // in obj files, indices must start from 1
+ if (index >= maxVal) return false;
+ if (index == -1) return false;
if (index < 0)
{
index += maxVal+1;
- if (index<0 || index > maxVal) return false;
+ if (index<0 || index >= maxVal) return false;
}
return true;
}
@@ -468,8 +469,16 @@
{
SplitToken(tokens[pi+1], indexVVect[pi],indexNVect[pi],indexTVect[pi], inputMask);
if(QuadFlag) indexVVect[pi]++; // NOTE THAT THE STUPID QOBJ FORMAT IS ZERO INDEXED!!!!
- GoodObjIndex(indexVVect[pi],numVertices);
- GoodObjIndex(indexTVect[pi],oi.numTexCoords);
+ if(!GoodObjIndex(indexVVect[pi],numVertices))
+ {
+ stream.close();
+ return E_BAD_VERT_INDEX;
+ }
+ if(!GoodObjIndex(indexTVect[pi],oi.numTexCoords) && ( oi.mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ))
+ {
+ stream.close();
+ return E_BAD_VERT_TEX_INDEX;
+ }
polygonVect[0][pi].Import(m.vert[indexVVect[pi]].cP());
}
if(vertexesPerFace>3)

