|
| 1 | +From aea471bdcb78188fbee20a081e5cebcbbd9d34a9 Mon Sep 17 00:00:00 2001 |
| 2 | +From: "A. Unique TensorFlower" <gardener@tensorflow.org> |
| 3 | +Date: Mon, 15 Dec 2025 13:20:46 -0800 |
| 4 | +Subject: [PATCH] Disable HDF5 plugin loading when importing h5py in |
| 5 | + Tensorflow. |
| 6 | + |
| 7 | +Set the HDF5_PLUGIN_PATH environment variable to "disable" before importing h5py to prevent the loading of external HDF5 plugins. |
| 8 | + |
| 9 | +PiperOrigin-RevId: 844896565 |
| 10 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 11 | +Upstream-reference: https://github.com/tensorflow/tensorflow/commit/46e7f7fb144fd11cf6d17c23dd47620328d77082.patch |
| 12 | +--- |
| 13 | + tensorflow/python/keras/engine/training.py | 3 +++ |
| 14 | + tensorflow/python/keras/keras_parameterized.py | 4 ++++ |
| 15 | + tensorflow/python/keras/saving/hdf5_format.py | 3 +++ |
| 16 | + tensorflow/python/keras/saving/save.py | 5 ++++- |
| 17 | + 4 files changed, 14 insertions(+), 1 deletion(-) |
| 18 | + |
| 19 | +diff --git a/tensorflow/python/keras/engine/training.py b/tensorflow/python/keras/engine/training.py |
| 20 | +index 1e94ca45..182db7b0 100644 |
| 21 | +--- a/tensorflow/python/keras/engine/training.py |
| 22 | ++++ b/tensorflow/python/keras/engine/training.py |
| 23 | +@@ -83,6 +83,9 @@ from tensorflow.tools.docs import doc_controls |
| 24 | + |
| 25 | + # pylint: disable=g-import-not-at-top |
| 26 | + try: |
| 27 | ++ # Disable loading HDF5 plugins from a default path and prevent ZDI-CAN-25480. |
| 28 | ++ # Importing h5py prior to importing tensorflow will restore the old behavior. |
| 29 | ++ os.environ['HDF5_PLUGIN_PATH'] = 'disable' |
| 30 | + import h5py |
| 31 | + except ImportError: |
| 32 | + h5py = None |
| 33 | +diff --git a/tensorflow/python/keras/keras_parameterized.py b/tensorflow/python/keras/keras_parameterized.py |
| 34 | +index 054df939..1a44e6b7 100644 |
| 35 | +--- a/tensorflow/python/keras/keras_parameterized.py |
| 36 | ++++ b/tensorflow/python/keras/keras_parameterized.py |
| 37 | +@@ -17,6 +17,7 @@ |
| 38 | + import collections |
| 39 | + import functools |
| 40 | + import itertools |
| 41 | ++import os |
| 42 | + import unittest |
| 43 | + |
| 44 | + from absl.testing import parameterized |
| 45 | +@@ -30,6 +31,9 @@ from tensorflow.python.platform import test |
| 46 | + from tensorflow.python.util import nest |
| 47 | + |
| 48 | + try: |
| 49 | ++ # Disable loading HDF5 plugins from a default path and prevent ZDI-CAN-25480. |
| 50 | ++ # Importing h5py prior to importing tensorflow will restore the old behavior. |
| 51 | ++ os.environ['HDF5_PLUGIN_PATH'] = 'disable' |
| 52 | + import h5py # pylint:disable=g-import-not-at-top |
| 53 | + except ImportError: |
| 54 | + h5py = None |
| 55 | +diff --git a/tensorflow/python/keras/saving/hdf5_format.py b/tensorflow/python/keras/saving/hdf5_format.py |
| 56 | +index 1f6bbc43..05a2c928 100644 |
| 57 | +--- a/tensorflow/python/keras/saving/hdf5_format.py |
| 58 | ++++ b/tensorflow/python/keras/saving/hdf5_format.py |
| 59 | +@@ -34,6 +34,9 @@ from tensorflow.python.platform import tf_logging as logging |
| 60 | + |
| 61 | + # pylint: disable=g-import-not-at-top |
| 62 | + try: |
| 63 | ++ # Disable loading HDF5 plugins from a default path and prevent ZDI-CAN-25480. |
| 64 | ++ # Importing h5py prior to importing tensorflow will restore the old behavior. |
| 65 | ++ os.environ['HDF5_PLUGIN_PATH'] = 'disable' |
| 66 | + import h5py |
| 67 | + HDF5_OBJECT_HEADER_LIMIT = 64512 |
| 68 | + except ImportError: |
| 69 | +diff --git a/tensorflow/python/keras/saving/save.py b/tensorflow/python/keras/saving/save.py |
| 70 | +index eee85923..b9ba0bc2 100644 |
| 71 | +--- a/tensorflow/python/keras/saving/save.py |
| 72 | ++++ b/tensorflow/python/keras/saving/save.py |
| 73 | +@@ -13,7 +13,7 @@ |
| 74 | + # limitations under the License. |
| 75 | + # ============================================================================== |
| 76 | + """Keras model saving code.""" |
| 77 | +- |
| 78 | ++import os |
| 79 | + from tensorflow.python import tf2 |
| 80 | + from tensorflow.python.keras.saving import hdf5_format |
| 81 | + from tensorflow.python.keras.saving import saving_utils |
| 82 | +@@ -25,6 +25,9 @@ from tensorflow.python.keras.utils.io_utils import path_to_string |
| 83 | + |
| 84 | + # pylint: disable=g-import-not-at-top |
| 85 | + try: |
| 86 | ++ # Disable loading HDF5 plugins from a default path and prevent ZDI-CAN-25480. |
| 87 | ++ # Importing h5py prior to importing tensorflow will restore the old behavior. |
| 88 | ++ os.environ['HDF5_PLUGIN_PATH'] = 'disable' |
| 89 | + import h5py |
| 90 | + except ImportError: |
| 91 | + h5py = None |
| 92 | +-- |
| 93 | +2.45.4 |
| 94 | + |
0 commit comments