Skip to content

Commit 640e08b

Browse files
ratgrtensorflower-gardener
authored andcommitted
Improve security of cache directory fallback.
PiperOrigin-RevId: 931219287
1 parent 6b15c7b commit 640e08b

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

tf_keras/utils/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ py_library(
6262
":generic_utils",
6363
":io_utils",
6464
":tf_inspect",
65+
"@pypi//numpy",
66+
"//:tf_nightly_with_deps", # "//third_party/py/tensorflow:tensorflow_core"
67+
# "//third_party/tensorflow/python/util:core",
6568
],
6669
)
6770

tf_keras/utils/data_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import random
2626
import shutil
2727
import tarfile
28+
import tempfile
2829
import threading
2930
import time
3031
import typing
@@ -275,6 +276,10 @@ def get_file(
275276
datadir_base = os.path.expanduser(cache_dir)
276277
if not os.access(datadir_base, os.W_OK):
277278
datadir_base = os.path.join("/tmp", ".keras")
279+
if os.path.exists(datadir_base):
280+
stat = os.stat(datadir_base)
281+
if stat.st_uid != os.getuid():
282+
datadir_base = tempfile.mkdtemp(prefix="keras_")
278283
datadir = os.path.join(datadir_base, cache_subdir)
279284
_makedirs_exist_ok(datadir)
280285

0 commit comments

Comments
 (0)