text
stringclasses
220 values
the file is by definition trusted and the limit is unnecessary.
Returns
-------
array : ndarray
The array from the data on disk.
Raises
------
ValueError
If the data is invalid, or allow_pickle=False and the file contains
an object array.
"""
if allow_pickle:
# Effectively ignore max_header_size, since `allow_pickle` indicates
# that the input is fully trusted.
max_header_size = 2**64
version = read_magic(fp)
_check_version(version)
shape, fortran_order, dtype = _read_array_header(
fp, version, max_header_size=max_header_size)
if len(shape) == 0:
count = 1
else:
count = numpy.multiply.reduce(shape, dtype=numpy.int64)
# Now read the actual data.
if dtype.hasobject:
# The array contained Python objects. We need to unpickle the data.
if not allow_pickle:
> raise ValueError("Object arrays cannot be loaded when "
"allow_pickle=False")
E ValueError: Object arrays cannot be loaded when allow_pickle=False
/usr/local/lib/python3.12/site-packages/numpy/lib/format.py:822: ValueError
_____ ERROR at setup of test_hidden_probes_and_malformed_input_fail_closed _____
isolation_root = PosixPath('/tmp/mesoscopic-verifier-1yow8xf0')
@pytest.fixture(scope="module")
def hidden_runs(
isolation_root: Path,
) -> tuple[
dict[str, Any],
dict[str, np.ndarray],
Path,
Path,
np.ndarray,
list[dict[str, Any]],
]:
HIDDEN_DIR.mkdir(parents=True, exist_ok=True)
config_path = HIDDEN_DIR / "hidden_config.json"
config_path.write_text(json.dumps(hidden_config(), indent=2, sort_keys=True) + "\n")
first_dir = HIDDEN_DIR / "run_a"
second_dir = HIDDEN_DIR / "run_b"
for directory in (first_dir, second_dir):
completed = run_submission(config_path, directory, isolation_root)
(HIDDEN_DIR / f"{directory.name}.log").write_text(completed.stdout)
assert completed.returncode == 0, completed.stdout
for filename in ("sweep_results.json", "samples.npz"):
artifact = directory / filename
assert artifact.is_file() and not artifact.is_symlink()
> first_result, first_arrays = validate_result_and_archive(
config_path,
first_dir / "sweep_results.json",
first_dir / "samples.npz",
)
/verifier/test_outputs.py:656:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/verifier/test_outputs.py:179: in validate_result_and_archive
arrays = load_archive(archive_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^
/verifier/test_outputs.py:88: in load_archive
return {name: np.array(archive[name], copy=True) for name in archive.files}
^^^^^^^^^^^^^
/usr/local/lib/python3.12/site-packages/numpy/lib/_npyio_impl.py:258: in __getitem__
return format.read_array(bytes,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fp = <zipfile.ZipExtFile name='model_names.npy' mode='r'>, allow_pickle = False
pickle_kwargs = {'encoding': 'ASCII', 'fix_imports': True}
def read_array(fp, allow_pickle=False, pickle_kwargs=None, *,
max_header_size=_MAX_HEADER_SIZE):
"""
Read an array from an NPY file.
Parameters
----------
fp : file_like object
If this is not a real file object, then this may take extra memory
and time.
allow_pickle : bool, optional
Whether to allow writing pickled data. Default: False
.. versionchanged:: 1.16.3
Made default False in response to CVE-2019-6446.