Commit e29d0ef
Version bump and cherry picks for 3.13.2 (#22080)
* Fix DoS via malicious HDF5 dataset metadata in KerasFileEditor (#21880)
* Fix DoS via malicious HDF5 dataset metadata in KerasFileEditor
* Refactor: move MAX_BYTES constant outside loop per review feedback
* Fix: harden HDF5 dataset metadata validation in KerasFileEditor
* Do not allow external links in HDF5 files. (#22057)
Keras never uses this feature.
- verify that we get H5 Groups when expected, otherwise, merely by doing `[key]` we may be loading an external Dataset.
- verify that the H5 Datasets are not external links and fail if they are.
- remove unused methods `items` and `values` in `H5IOStore` and `ShardedH5IOStore`. They are not used, the implementation of `MutableMapping` was incomplete anyway and these methods we return unverified Datasets.
- fixed logic related to `failed_saveables` in `load_state`.
- preserve the order of keys in the implementation of `ShardedH5IOStore.keys()`.
* Set mutable to True by default in nnx_metadata (#22074)
* Disallow TFSMLayer deserialization in safe_mode to prevent external SavedModel execution (#22035)
* Implement safe mode checks in TFSMLayer
Added safe mode checks for loading TFSMLayer from external SavedModels.
* Update keras/src/export/tfsm_layer.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
* Align logic with __init__ method for robust checks
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
* Fix indentation and formatting in tfsm_layer.py
* Add setup method to enable unsafe deserialization
Enable unsafe deserialization for TFSM Layer tests.
* Update TFSMLayer initialization in tests
* Fix import for TFSMLayer in tfsm_layer_test.py
* Remove safe_mode check from TFSMLayer.__init__()
The safe_mode check should only be in from_config(), not __init__().
Direct instantiation (TFSMLayer(filepath=...)) is a legitimate use case
where the user explicitly creates the layer. The security concern is
only during deserialization of untrusted .keras files, which goes
through from_config().
This allows attackers to create malicious .keras files while still
blocking victims from loading them with safe_mode=True.
* Implement tests for TFSMLayer safe mode functionality
Add comprehensive tests for TFSMLayer safe_mode behavior:
- test_safe_mode_direct_instantiation_allowed: Verifies direct
TFSMLayer instantiation works as expected
- test_safe_mode_from_config_blocked: Verifies from_config() raises
ValueError when safe_mode=True
- test_safe_mode_from_config_allowed_when_disabled: Verifies
from_config() works with safe_mode=False
- test_safe_mode_model_loading_blocked: Tests the full attack scenario
where loading a .keras file with safe_mode=True is blocked
* Clarify test docstrings in tfsm_layer_test.py
Updated test docstrings for clarity on instantiation and loading behavior.
* Invoke model with random input in tfsm_layer tests
Added model invocation with random input to tests for TFSMLayer.
* Set safe_mode default to True in from_config method
* Update tfsm_layer_test.py
* Update tfsm_layer_test.py
* Update tfsm_layer_test.py to original
* New test case tfsm_layer_test.py
* Update Comments tfsm_layer.py
* Update tfsm_layer_test.py
* Update tfsm_layer.py
* Update tfsm_layer.py to remove ruff errors
* Update tfsm_layer.py
* Update tfsm_layer_test.py
* Update tfsm_layer.py
* Update tfsm_layer.py
* Update tfsm_layer_test.py
* Update tfsm_layer.py format fix
Changes in format
* Update tfsm_layer.py
* Update tfsm_layer_test.py
* Update tfsm_layer.py
* Update tfsm_layer_test.py
* Fixes unnecessary changes tfsm_layer.py
* Added new test case tfsm_layer_test.py
* Set `safe_mode=None` in `from_config`, which fixes the unit tests.
Also re-added empty lines.
* Remove unneeded `custom_objects` in unit tests.
---------
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Fabien Hertschuh <1091026+hertschuh@users.noreply.github.com>
* patch release 3.12.2 changes
---------
Co-authored-by: sarvesh patil <103917093+HyperPS@users.noreply.github.com>
Co-authored-by: hertschuh <1091026+hertschuh@users.noreply.github.com>
Co-authored-by: Divyashree Sreepathihalli <divyashreepathihalli@gmail.com>
Co-authored-by: Manan Patel <70314133+0xManan@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>1 parent 8914427 commit e29d0ef
File tree
7 files changed
+201
-76
lines changed- keras/src
- backend/jax
- export
- saving
7 files changed
+201
-76
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
125 | | - | |
126 | | - | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
130 | 159 | | |
131 | 160 | | |
132 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
458 | 461 | | |
459 | 462 | | |
460 | 463 | | |
461 | 464 | | |
462 | 465 | | |
463 | 466 | | |
464 | 467 | | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
465 | 472 | | |
466 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
467 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
468 | 481 | | |
| 482 | + | |
469 | 483 | | |
470 | 484 | | |
| 485 | + | |
| 486 | + | |
471 | 487 | | |
472 | 488 | | |
473 | 489 | | |
474 | | - | |
| 490 | + | |
475 | 491 | | |
476 | 492 | | |
477 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
478 | 496 | | |
479 | 497 | | |
| 498 | + | |
480 | 499 | | |
481 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
482 | 503 | | |
483 | | - | |
484 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
485 | 566 | | |
486 | 567 | | |
487 | 568 | | |
| |||
0 commit comments