Package: libvtk9.6 Version: 9.6.2+ds-5 Severity: important Hi,
while investigating a i386 build failure of another package, a LLM
tracked back one of the problems to different struct sizes between
parts of VTK on i386, see the report below.
I have not investigated manually, but it seems plausible enough.
Ansgar
---
Dear Maintainer,
on i386, vtkXMLReader::CanReadFile() returns 0 for every file, however
small, with
vtkXMLReader.cxx:1611 ERR| vtkXMLUnstructuredGridReader: Unable to read
file, Expat must be configured with XML_LARGE_SIZE to read files > 2Gb: t.vtu
The serial readers do not call CanReadFile(), so reading a .vtu directly
works. The parallel readers check every piece with it (vtkXMLPDataReader::
CanReadPiece()), so no .pvtu/.pvtp file can be read on i386: "File for
piece 0 cannot be read", 0 cells. Found through dune-grid's VTK tests.
Reproducer (python3-vtk9 only; attached as repro-pvtu.py): write a grid
with two triangles as t.vtu and as a two-piece t.pvtu, read both back.
i386 (9.6.2+ds-5):
files: {'t.pvtu': 385, 't.vtu': 1355, 't_0.vtu': 1631, 't_1.vtu': 1631}
vtkXMLUnstructuredGridReader.CanReadFile('t.vtu') = 0
t.vtu cells: 2
t.pvtu cells: 0 (both pieces hold the whole grid: 4 expected)
amd64 (9.6.2+ds-5):
vtkXMLUnstructuredGridReader.CanReadFile('t.vtu') = 1
t.vtu cells: 2
t.pvtu cells: 4
Cause: libvtksys and the rest of VTK disagree about struct stat on i386.
- VTK's own code is compiled with large file support:
Common/Core/vtkWin32Header.h (included through vtkSystemIncludes.h)
defines _FILE_OFFSET_BITS 64 when VTK_REQUIRE_LARGE_FILE_SUPPORT is set,
and the check in CMakeLists.txt:150-154 sets it.
- The bundled KWSys (libvtksys) does not include that header, and
dpkg-buildflags does not enable LFS on i386 (only together with time64,
which i386 does not have). So libvtksys has the 32-bit off_t ABI:
vtksys::SystemTools::Stat(const char*, struct stat*) calls
stat@GLIBC_2.33 and fills an 88-byte struct stat. Its callers in VTK pass
the 96-byte LFS struct stat.
- vtkXMLReader::CanReadFile() (IO/XML/vtkXMLReader.cxx:1580-1615) reads
st_size as a 64-bit value at offset 44. The low word is the real size,
but the high word is st_blksize from the 32-bit layout (4096). So a
9389-byte file appears as 4096 * 2^32 + 9389 = 17592186053805 bytes,
which is > VTK_LONG_MAX, and Debian's expat lacks XML_LARGE_SIZE.
Machine code: the comparison at libvtkIOXML-9.6.so.9.6 offset 0xa67ea
reads -0x80(%ebp) and -0x7c(%ebp) of the Stat_t at -0xac(%ebp).
Minimal demonstration without VTK headers (attached as stat-abi.cc):
calling vtksys::SystemTools::Stat() on a 9389-byte file from libvtksys-9.6
on i386 gives
caller without LFS: sizeof(struct stat)=88 st_size=9389
caller with _FILE_OFFSET_BITS=64 (as vtkXMLReader.cxx):
sizeof(struct stat)=96 st_size=17592186053805
Other architectures are not affected: on armhf (time64, hence LFS by
default) libvtksys imports __stat64_time64, and the 64-bit architectures
have only one layout. Other callers of SystemTools::Stat() that use
st_size or later fields (st_mtime, ...) are presumably affected on i386
too, e.g. vtkImageReader2, vtkLSDynaReader and the MINC readers (not
checked individually).
Confirmation of the cause: I rebuilt only Utilities/KWSys of 9.6.2+ds-5 on
i386 with -D_FILE_OFFSET_BITS=64 (same KWSYS_* settings as
Utilities/KWSys/CMakeLists.txt) and put it in place of
libvtksys-9.6.so.9.6. CanReadFile() then returns 1, and the .pvtu files of
dune-grid's tests are read.
Possible fixes (I have not built the whole package with either):
- build vtk9 with large file support everywhere, e.g.
"export DEB_BUILD_MAINT_OPTIONS += abi=+lfs" in debian/rules. That
changes nothing on 64-bit and time64 architectures, and on i386 it makes
libvtksys match the rest of VTK. Programs compiled without LFS that call
libvtksys functions taking struct stat directly (rather than through VTK
headers, which already enable LFS) would then pass a struct that is too
small. I do not know of any.
- or compile only KWSys with _FILE_OFFSET_BITS=64 when
VTK_REQUIRE_LARGE_FILE_SUPPORT is set (an upstream change in
Utilities/KWSys/CMakeLists.txt).
Upstream master no longer calls Stat() in CanReadFile(const char*): since
00bfc85f "vtkXMLReader: Add CanReadFile(stream) support", which postdates
9.6, it takes the size from a vtkResourceStream. The mismatch itself
remains.
# Write a tiny unstructured grid with VTK as .vtu and as a 2-piece .pvtu, then
# read both back. Only python3-vtk9 needed.
import os, tempfile
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid, VTK_TRIANGLE
from vtkmodules.vtkIOXML import (vtkXMLUnstructuredGridWriter, vtkXMLUnstructuredGridReader,
vtkXMLPUnstructuredGridReader)
from vtkmodules.vtkIOParallelXML import vtkXMLPUnstructuredGridWriter
os.chdir(tempfile.mkdtemp())
g = vtkUnstructuredGrid(); p = vtkPoints()
for x, y in [(0, 0), (1, 0), (0, 1), (1, 1)]: p.InsertNextPoint(x, y, 0)
g.SetPoints(p); g.InsertNextCell(VTK_TRIANGLE, 3, [0, 1, 2]); g.InsertNextCell(VTK_TRIANGLE, 3, [1, 3, 2])
w = vtkXMLUnstructuredGridWriter(); w.SetFileName("t.vtu"); w.SetInputData(g); w.Write()
w = vtkXMLPUnstructuredGridWriter(); w.SetFileName("t.pvtu"); w.SetInputData(g)
w.SetNumberOfPieces(2); w.SetStartPiece(0); w.SetEndPiece(1); w.Write()
print("files:", {f: os.path.getsize(f) for f in sorted(os.listdir("."))})
r = vtkXMLUnstructuredGridReader()
print("vtkXMLUnstructuredGridReader.CanReadFile('t.vtu') =", r.CanReadFile("t.vtu"))
r.SetFileName("t.vtu"); r.Update(); print("t.vtu cells:", r.GetOutput().GetNumberOfCells())
r = vtkXMLPUnstructuredGridReader(); r.SetFileName("t.pvtu"); r.Update()
print("t.pvtu cells:", r.GetOutput().GetNumberOfCells(), "(both pieces hold the whole grid: 4 expected)")
repro-pvtu.sh
Description: application/shellscript
// Calls vtksys::SystemTools::Stat() from libvtksys-9.6 (no VTK headers needed:
// the function is declared here with the same signature) and prints st_size.
// Build once without and once with -D_FILE_OFFSET_BITS=64: the latter is what
// VTK's own code (vtkSystemIncludes.h -> vtkWin32Header.h) is compiled with.
#include <sys/stat.h>
#include <cstdio>
namespace vtksys { struct SystemTools { static int Stat(const char* path, struct stat* buf); }; }
int main(int argc, char** argv)
{
struct stat st;
int r = vtksys::SystemTools::Stat(argv[1], &st);
struct stat ref;
stat(argv[1], &ref);
std::printf("sizeof(struct stat)=%zu vtksys Stat()=%d st_size=%lld (stat(): %lld)\n",
sizeof(st), r, (long long)st.st_size, (long long)ref.st_size);
return 0;
}
stat-abi.sh
Description: application/shellscript

