onnx 1.16.1__cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl → 1.16.2__cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of onnx might be problematic. Click here for more details.

@@ -10,7 +10,6 @@ import os
10
10
  import re
11
11
  import shutil
12
12
  import sys
13
- import tarfile
14
13
  import tempfile
15
14
  import time
16
15
  import unittest
@@ -238,8 +237,7 @@ class Runner:
238
237
  )
239
238
  urlretrieve(model_test.url, download_file.name)
240
239
  print("Done")
241
- with tarfile.open(download_file.name) as t:
242
- t.extractall(models_dir)
240
+ onnx.utils._extract_model_safe(download_file.name, models_dir)
243
241
  except Exception as e:
244
242
  print(f"Failed to prepare data for model {model_test.model_name}: {e}")
245
243
  raise
onnx/common/version.h CHANGED
@@ -9,6 +9,6 @@
9
9
  namespace ONNX_NAMESPACE {
10
10
 
11
11
  // Represents the most recent release version. Updated with every release.
12
- constexpr const char* LAST_RELEASE_VERSION = "1.16.1";
12
+ constexpr const char* LAST_RELEASE_VERSION = "1.16.2";
13
13
 
14
14
  } // namespace ONNX_NAMESPACE
onnx/defs/math/old.cc CHANGED
@@ -2322,10 +2322,15 @@ ONNX_OPERATOR_SET_SCHEMA(
2322
2322
  auto transBAttr = ctx.getAttribute("transB");
2323
2323
  bool transB = transBAttr ? static_cast<int>(transBAttr->i()) != 0 : false;
2324
2324
 
2325
+ checkInputRank(ctx, 0, 2);
2326
+ checkInputRank(ctx, 1, 2);
2327
+
2328
+ auto& first_input_shape = getInputShape(ctx, 0);
2329
+ auto& second_input_shape = getInputShape(ctx, 1);
2325
2330
  *ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape()->add_dim() =
2326
- ctx.getInputType(0)->tensor_type().shape().dim(transA ? 1 : 0);
2331
+ first_input_shape.dim(transA ? 1 : 0);
2327
2332
  *ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape()->add_dim() =
2328
- ctx.getInputType(1)->tensor_type().shape().dim(transB ? 0 : 1);
2333
+ second_input_shape.dim(transB ? 0 : 1);
2329
2334
  } else if (
2330
2335
  hasInputShape(ctx, 2) &&
2331
2336
  (!ctx.getAttribute("broadcast") || static_cast<int>(ctx.getAttribute("broadcast")->i()) == 0)) {
onnx/defs/tensor/old.cc CHANGED
@@ -1380,7 +1380,7 @@ ONNX_OPERATOR_SET_SCHEMA(
1380
1380
 
1381
1381
  static const char* Slice_ver11_doc = R"DOC(
1382
1382
  Produces a slice of the input tensor along multiple axes. Similar to numpy:
1383
- https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
1383
+ https://numpy.org/doc/stable/reference/routines.indexing.html
1384
1384
  Slices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end
1385
1385
  dimension and step for each axis in the list of axes, it uses this information to
1386
1386
  slice the input `data` tensor. If a negative value is passed for any of the
@@ -4443,7 +4443,7 @@ ONNX_OPERATOR_SET_SCHEMA(
4443
4443
 
4444
4444
  static const char* Slice_ver1_doc = R"DOC(
4445
4445
  Produces a slice of the input tensor along multiple axes. Similar to numpy:
4446
- https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
4446
+ https://numpy.org/doc/stable/reference/routines.indexing.html
4447
4447
  Slices uses `axes`, `starts` and `ends` attributes to specify the start and end
4448
4448
  dimension for each axis in the list of axes, it uses this information to
4449
4449
  slice the input `data` tensor. If a negative value is passed for any of the
@@ -4559,7 +4559,7 @@ ONNX_OPERATOR_SET_SCHEMA(
4559
4559
 
4560
4560
  static const char* Slice_ver10_doc = R"DOC(
4561
4561
  Produces a slice of the input tensor along multiple axes. Similar to numpy:
4562
- https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
4562
+ https://numpy.org/doc/stable/reference/routines.indexing.html
4563
4563
  Slices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end
4564
4564
  dimension and step for each axis in the list of axes, it uses this information to
4565
4565
  slice the input `data` tensor. If a negative value is passed for any of the
onnx/hub.py CHANGED
@@ -9,7 +9,6 @@ import hashlib
9
9
  import json
10
10
  import os
11
11
  import sys
12
- import tarfile
13
12
  from io import BytesIO
14
13
  from os.path import join
15
14
  from typing import IO, Any, Dict, List, Optional, Set, Tuple, cast
@@ -296,6 +295,7 @@ def download_model_with_test_data(
296
295
  silent: bool = False,
297
296
  ) -> Optional[str]:
298
297
  """Downloads a model along with test data by name from the onnx model hub and returns the directory to which the files have been extracted.
298
+ Users are responsible for making sure the model comes from a trusted source, and the data is safe to be extracted.
299
299
 
300
300
  Args:
301
301
  model: The name of the onnx model in the manifest. This field is
@@ -361,12 +361,14 @@ def download_model_with_test_data(
361
361
  "download the model from the model hub."
362
362
  )
363
363
 
364
- with tarfile.open(local_model_with_data_path) as model_with_data_zipped:
365
- # FIXME: Avoid index manipulation with magic numbers
366
- local_model_with_data_dir_path = local_model_with_data_path[
367
- 0 : len(local_model_with_data_path) - 7
368
- ]
369
- model_with_data_zipped.extractall(local_model_with_data_dir_path)
364
+ # FIXME: Avoid index manipulation with magic numbers,
365
+ # remove ".tar.gz"
366
+ local_model_with_data_dir_path = local_model_with_data_path[
367
+ 0 : len(local_model_with_data_path) - 7
368
+ ]
369
+ onnx.utils._extract_model_safe(
370
+ local_model_with_data_path, local_model_with_data_dir_path
371
+ )
370
372
  model_with_data_path = (
371
373
  local_model_with_data_dir_path
372
374
  + "/"
onnx/tools/net_drawer.py CHANGED
@@ -3,7 +3,7 @@
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
  # A library and utility for drawing ONNX nets. Most of this implementation has
5
5
  # been borrowed from the caffe2 implementation
6
- # https://github.com/pytorch/pytorch/blob/master/caffe2/python/net_drawer.py
6
+ # https://github.com/pytorch/pytorch/blob/v2.3.1/caffe2/python/net_drawer.py
7
7
  #
8
8
  # The script takes two required arguments:
9
9
  # -input: a path to a serialized ModelProto .pb file.
onnx/utils.py CHANGED
@@ -4,6 +4,7 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import os
7
+ import tarfile
7
8
 
8
9
  import onnx.checker
9
10
  import onnx.helper
@@ -212,3 +213,65 @@ def extract_model(
212
213
  onnx.save(extracted, output_path)
213
214
  if check_model:
214
215
  onnx.checker.check_model(output_path)
216
+
217
+
218
+ def _tar_members_filter(
219
+ tar: tarfile.TarFile, base: str | os.PathLike
220
+ ) -> list[tarfile.TarInfo]:
221
+ """Check that the content of ``tar`` will be extracted safely
222
+
223
+ Args:
224
+ tar: The tarball file
225
+ base: The directory where the tarball will be extracted
226
+
227
+ Returns:
228
+ list of tarball members
229
+ """
230
+ result = []
231
+ for member in tar:
232
+ member_path = os.path.join(base, member.name)
233
+ abs_base = os.path.abspath(base)
234
+ abs_member = os.path.abspath(member_path)
235
+ if not abs_member.startswith(abs_base):
236
+ raise RuntimeError(
237
+ f"The tarball member {member_path} in downloading model contains "
238
+ f"directory traversal sequence which may contain harmful payload."
239
+ )
240
+ elif member.issym() or member.islnk():
241
+ raise RuntimeError(
242
+ f"The tarball member {member_path} in downloading model contains "
243
+ f"symbolic links which may contain harmful payload."
244
+ )
245
+ result.append(member)
246
+ return result
247
+
248
+
249
+ def _extract_model_safe(
250
+ model_tar_path: str | os.PathLike, local_model_with_data_dir_path: str | os.PathLike
251
+ ) -> None:
252
+ """Safely extracts a tar file to a specified directory.
253
+
254
+ This function ensures that the extraction process mitigates against
255
+ directory traversal vulnerabilities by validating or sanitizing paths
256
+ within the tar file. It also provides compatibility for different versions
257
+ of the tarfile module by checking for the availability of certain attributes
258
+ or methods before invoking them.
259
+
260
+ Args:
261
+ model_tar_path: The path to the tar file to be extracted.
262
+ local_model_with_data_dir_path: The directory path where the tar file
263
+ contents will be extracted to.
264
+ """
265
+ with tarfile.open(model_tar_path) as model_with_data_zipped:
266
+ # Mitigate tarball directory traversal risks
267
+ if hasattr(tarfile, "data_filter"):
268
+ model_with_data_zipped.extractall(
269
+ path=local_model_with_data_dir_path, filter="data"
270
+ )
271
+ else:
272
+ model_with_data_zipped.extractall(
273
+ path=local_model_with_data_dir_path,
274
+ members=_tar_members_filter(
275
+ model_with_data_zipped, local_model_with_data_dir_path
276
+ ),
277
+ )
onnx/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  # This file is generated by setup.py. DO NOT EDIT!
2
2
 
3
3
 
4
- version = "1.16.1"
4
+ version = "1.16.2"
5
5
  git_version = ""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: onnx
3
- Version: 1.16.1
3
+ Version: 1.16.2
4
4
  Summary: Open Neural Network Exchange
5
5
  Author-email: ONNX Contributors <onnx-technical-discuss@lists.lfaidata.foundation>
6
6
  License: Apache License v2.0
@@ -14,7 +14,7 @@ Requires-Dist: numpy >=1.20
14
14
  Requires-Dist: protobuf >=3.20.2
15
15
  Provides-Extra: reference
16
16
  Requires-Dist: google-re2 ; extra == 'reference'
17
- Requires-Dist: Pillow ; extra == 'reference'
17
+ Requires-Dist: pillow ; extra == 'reference'
18
18
 
19
19
  <!--
20
20
  Copyright (c) ONNX Project Contributors