Summary
PyTables can interpret certain NumPy byte-string attributes in an HDF5 file as pickled Python objects and deserialize them when the attributes are accessed. Reading a crafted file's affected metadata may execute attacker-controlled code in the process consuming the file.
Affected context
The issue occurs in PyTables attribute handling when an attribute is accessed through AttributeSet.__getattr__ or AttributeSet.__getitem__. In versions 3.11.1 and earlier, a NumPy bytes scalar ending in a period can be treated as a pickled object and passed to pickle.loads(). Risk arises when an application opens an attacker-controlled HDF5 file and reads an affected metadata attribute.
Exploit preconditions
- Attack surface: Processing an HDF5 file with PyTables.
- Required access: An attacker must be able to provide or influence the file being processed; direct access to the consumer's system is not necessarily required.
- Trigger point: Accessing an affected metadata attribute through
AttributeSet.__getattr__orAttributeSet.__getitem__. - Why exploitation is possible: The attribute handling logic may pass attacker-controlled data to Python's pickle deserializer.
Why this happens
PyTables uses the content and shape of a NumPy bytes scalar to identify values as pickled objects, then calls pickle.loads() during attribute access. Pickle deserialization can invoke object construction behavior, so applying it to untrusted file metadata can execute attacker-controlled code. This is CWE-502: Deserialization of Untrusted Data.
Potential impact
- Attacker-controlled code may execute in the process reading the HDF5 file.
- The process's accessible data or credentials could be exposed or modified.
- The host or service running the consumer could be compromised, subject to its permissions.
- Further systems or data accessible to the consumer could be affected.
General mitigation guidance
Defensive approaches focus on avoiding executable deserialization of file metadata and reducing trust in externally supplied data.
- Prefer non-executable, explicitly typed serialization formats for metadata.
- Treat HDF5 files and their attributes as untrusted, even when they come from routine data workflows.
- Validate attribute types and schemas without invoking pickle or other executable deserializers.
- Where legacy formats must be handled, isolate file processing and limit the process's filesystem, network, and credential access.
- Apply least-privilege permissions and avoid granting file-processing workers access beyond what their task requires.
How teams detect issues like this
- Use static analysis to identify
pickle.loads()and other executable deserialization calls reachable from file or metadata parsing. - Review attribute access paths for format heuristics that dispatch input to deserializers.
- Add tests and security checks that exercise malformed or externally supplied HDF5 metadata without executing it.
- Enforce code-review or CI policies that prohibit unsafe deserialization of untrusted data; automated review tools may help flag relevant patterns.

