Bug#1153102: nexus: C++ binding overflows name buffers with HDF4 4.4.0

Sebastien Bacher seb128 at ubuntu.com
Thu Nov 5 12:35:38 GMT 2026


Source: nexus
Version: 4.4.3-11build1
Severity: important
Tags: patch
X-Debbugs-Cc: seb128 at ubuntu.com
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu tenacious ubuntu-patch

Hi,

Thanks for the HDF4 4.4.0 fixes in -12 and -13. The C++ binding has the
same buffer size mismatch that 0008-Fix-HDF4-test-buffer-size-mismatch.patch
fixed in test/napi_test.c, but in the library itself this time.

File::getNextEntry() and File::getNextAttr() in bindings/cpp/NeXusFile.cpp
declare their name/class buffers as char[NX_MAXNAMELEN] (64) and pass
them to NXgetnextentry()/NXgetnextattra(), which take NXname (char[128]).
The HDF4 backend calls Vgetname() with sizeof(NXname) as the buffer size
and HDF4 4.4.0 NUL-pads the whole buffer, so 64 bytes past the end of the
stack buffer get overwritten.

In Debian the build happens to pass, but in Ubuntu, which builds with
GCC 15 and -D_FORTIFY_SOURCE=3, 4.4.3-13 fails to build on amd64, arm64,
ppc64el and s390x:

  8: Number of group attributes: 2
  8:    hugo = namenlos
  8:    cucumber = passion
  8: *** stack smashing detected ***: terminated
   8/10 Test  #8: NAPI-C++-HDF4-test ...............Subprocess aborted

Since this is in libnexus1, any program using the C++ API to list the
entries of an HDF4 file is affected, not only the test.

The attached patch switches those three buffers to NXname. We're
carrying it in Ubuntu as 4.4.3-13ubuntu1.

Cheers,
Sebastien


-- System Information:
Debian Release: forky/sid
  APT prefers resolute-updates
  APT policy: (500, 'resolute-updates'), (500, 'resolute-security'), (500, 'resolute'), (100, 'resolute-backports')
Architecture: amd64 (x86_64)

Kernel: Linux 7.0.0-42-generic (SMP w/16 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_WARN, TAINT_OOT_MODULE
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
-------------- next part --------------
From: Sebastien Bacher <seb128 at ubuntu.com>
Date: Wed, 4 Nov 2026 10:00:00 +0100
Subject: Fix C++ binding name buffer size

The NeXus C API takes NXname (char[128]) buffers for names and classes,
and the HDF4 backend passes sizeof(NXname) as the buffer size to
Vgetname()/Vgetclass(). File::getNextEntry() and File::getNextAttr() in
the C++ binding declared those buffers as char[NX_MAXNAMELEN] (64).
HDF4 4.4.0 NUL-pads the whole buffer, so the write spills over the
stack. This is the same mismatch as the one fixed in test/napi_test.c,
and makes NAPI-C++-HDF4-test abort with "stack smashing detected"
depending on compiler and architecture (e.g. GCC 15 with
_FORTIFY_SOURCE=3 on amd64, arm64, ppc64el and s390x).

---
 bindings/cpp/NeXusFile.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bindings/cpp/NeXusFile.cpp b/bindings/cpp/NeXusFile.cpp
--- a/bindings/cpp/NeXusFile.cpp
+++ b/bindings/cpp/NeXusFile.cpp
@@ -1025,8 +1025,8 @@ Info File::getInfo() {
 
 pair<string, string> File::getNextEntry() {
   // set up temporary variables to get the information
-  char name[NX_MAXNAMELEN];
-  char class_name[NX_MAXNAMELEN];
+  NXname name;
+  NXname class_name;
   int datatype;
 
   NXstatus status = NXgetnextentry(this->m_file_id, name, class_name,
@@ -1099,7 +1099,7 @@ void File::getSlab(void* data, const vec
 
 AttrInfo File::getNextAttr() {
   //string & name, int & length, NXnumtype type) {
-  char name[NX_MAXNAMELEN];
+  NXname name;
   int type;
 
   int rank;


More information about the debian-science-maintainers mailing list