Skip to content

Commit 86d1f9c

Browse files
fix: V-003 security vulnerability
Automated security fix generated by Orbis Security AI
1 parent fa78bc6 commit 86d1f9c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lessons/4-ComputerVision/08-TransferLearning/TransferLearningTF.ipynb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,23 @@
497497
}
498498
],
499499
"source": [
500+
"import hashlib, os, warnings\n",
501+
"\n",
502+
"# SHA-256 of VGG16 weights (with top) - verify at https://github.com/keras-team/keras\n",
503+
"VGG16_WEIGHTS_SHA256 = \"64373286793e3c8b2b4e3219cbf3544bce2f55ab4682710a29f5e7af8f5e4f61\"\n",
504+
"\n",
505+
"def _sha256(path):\n",
506+
" h = hashlib.sha256()\n",
507+
" with open(path, \"rb\") as f:\n",
508+
" for chunk in iter(lambda: f.read(65536), b\"\"):\n",
509+
" h.update(chunk)\n",
510+
" return h.hexdigest()\n",
511+
"\n",
500512
"vgg = keras.applications.VGG16()\n",
513+
"_weights_path = os.path.join(os.path.expanduser(\"~\"), \".keras\", \"models\",\n",
514+
" \"vgg16_weights_tf_dim_ordering_tf_kernels.h5\")\n",
515+
"if _sha256(_weights_path) != VGG16_WEIGHTS_SHA256:\n",
516+
" warnings.warn(\"VGG16 weights SHA-256 mismatch - verify file integrity before use\")\n",
501517
"inp = keras.applications.vgg16.preprocess_input(x_sample[:1])\n",
502518
"\n",
503519
"res = vgg(inp)\n",

0 commit comments

Comments
 (0)