]> khamidou — GitHub mirrors - safetensors.git/commit
Fixing potential DOS attacks. (#26)
authorNicolas Patry <patry.nicolas@protonmail.com>
Thu, 20 Oct 2022 16:33:56 +0000 (18:33 +0200)
committerGitHub <noreply@github.com>
Thu, 20 Oct 2022 16:33:56 +0000 (18:33 +0200)
commit3e49a49b7b22c2851f0237aafea2cf2a145b26ba
treed9cfe80b0fe15df2384cb06e5fec9079fa17dd03
parent4fb5e2fbf8eea99089d1693a4b2f53a7b5993c21
 Fixing potential DOS attacks. (#26)

* Fixing potential DOS attacks.

- Fixed code sharing between rust package and python bindings in
  `safe_open` (where possible).
- Added a maximum size for the header (now hardcoded to 100Mo).
  A very large JSON header could indeed slow things down effectively
  (takes a few seconds to parse). This one is debattable.
- Added a safety check when deserializing the header.
  If offsets could overlap, then we could still DOS users because we
  could force them into allocating over and over the same buffer,
  leading to RAM explosion. This fixes it by checking out that the offset
  ranges are contiguous after loading the header.

* Make `Metadata::new()` faillible.

so we sanitize before writing to file.
bindings/python/src/lib.rs
safetensors/benches/benchmark.rs
safetensors/src/tensor.rs