diff --git a/raytracing/rays.py b/raytracing/rays.py
index 9129491..a424fad 100644
--- a/raytracing/rays.py
+++ b/raytracing/rays.py
@@ -207,6 +207,10 @@ class Rays:
     def load(self, filePath, append=False):
         with open(filePath, 'rb') as infile:
             loadedRays = pickle.Unpickler(infile).load()
+            if not isinstance(loadedRays, collections.Iterable):
+                raise IOError(f"{filePath} does not contain an iterable of Ray objects.")
+            if not all([isinstance(ray, Ray) for ray in loadedRays]):
+                raise IOError(f"{filePath} must contain only Ray objects.")
             if append and self._rays is not None:
                 self._rays.extend(loadedRays)
             else:

Rays can load any "pickled" file
This can lead to unwanted behaviors. We should check if the content of the file is an iterable of `Ray` objects.

`load` directly extends (or override) the inner list or rays in `Rays`. This can cause unexpected problems without proper guidance to what caused the issue.
diff --git a/raytracing/tests/testsRays.py b/raytracing/tests/testsRays.py
index 33ac2e3..833ade3 100644
--- a/raytracing/tests/testsRays.py
+++ b/raytracing/tests/testsRays.py
@@ -69,7 +69,6 @@ class TestRays(unittest.TestCase):
         r = Rays(listOfRays)
         self.assertEqual(len(r), len(listOfRays))
 
-
     def testRaysGetRay(self):
         raysList = [Ray(), Ray(1), Ray(-1)]
         rays = Rays(raysList)
@@ -244,7 +243,6 @@ class TestRays(unittest.TestCase):
         self.assertIsNone(r._anglesHistogramParameters)
         self.assertIsNone(r._xValuesAnglesHistogram)
 
-
     def testAppendInvalidInput(self):
         rays = Rays()
         with self.assertRaises(TypeError):
@@ -258,7 +256,7 @@ class TestRaysSaveAndLoad(unittest.TestCase):
         self.fileName = 'testFile.pkl'
         with open(self.fileName, 'wb') as file:
             pickle.Pickler(file).dump(self.testRays.rays)
-        time.sleep(1)  # Make sure everything is ok
+        time.sleep(0.5)  # Make sure everything is ok
 
     def tearDown(self) -> None:
         if os.path.exists(self.fileName):
@@ -294,6 +292,33 @@ class TestRaysSaveAndLoad(unittest.TestCase):
         self.assertLoadNotFailed(rays)  # We don't append, we override
         self.assertListEqual(rays.rays, self.testRays.rays)
 
+    def testLoadWrongFileContent(self):
+        wrongObj = 7734
+        fileName = 'wrongObj.pkl'
+        with open(fileName, 'wb') as file:
+            pickle.Pickler(file).dump(wrongObj)
+        time.sleep(0.5)  # Make sure everything is ok
+
+        try:
+            with self.assertRaises(IOError):
+                Rays().load(fileName)
+        except AssertionError as exception:
+            self.fail(str(exception))
+        finally:
+            os.remove(fileName)
+
+        wrongIterType = [Ray(), Ray(1), [1, 1]]
+        with open(fileName, 'wb') as file:
+            pickle.Pickler(file).dump(wrongIterType)
+        time.sleep(0.5)
+        try:
+            with self.assertRaises(IOError):
+                Rays().load(fileName)
+        except AssertionError as exception:
+            self.fail(str(exception))
+        finally:
+            os.remove(fileName)
+
     def assertSaveNotFailed(self, rays: Rays, name: str, deleteNow: bool = True):
         try:
             rays.save(name)

pip install -e .
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.9
docs/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.16
babel==2.17.0
certifi==2025.1.31
charset-normalizer==3.4.1
contourpy==1.3.0
cycler==0.12.1
docutils==0.21.2
exceptiongroup==1.2.2
fonttools==4.56.0
idna==3.10
imagesize==1.4.1
importlib_metadata==8.6.1
importlib_resources==6.5.2
iniconfig==2.1.0
Jinja2==3.1.6
kiwisolver==1.4.7
MarkupSafe==3.0.2
matplotlib==3.9.4
numpy==2.0.2
packaging==24.2
pillow==11.1.0
pluggy==1.5.0
Pygments==2.19.1
pyparsing==3.2.3
pytest==8.3.5
python-dateutil==2.9.0.post0
-e git+https://github.com/DCC-Lab/RayTracing.git@ce69bb2fc28ba9864f2631abd5e87819aad1de74#egg=raytracing
requests==2.32.3
six==1.17.0
snowballstemmer==2.2.0
Sphinx==7.4.7
sphinx-rtd-theme==0.4.3
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
tomli==2.2.1
urllib3==2.3.0
zipp==3.21.0

name: RayTracing
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.16
      - babel==2.17.0
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - contourpy==1.3.0
      - cycler==0.12.1
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - fonttools==4.56.0
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==8.6.1
      - importlib-resources==6.5.2
      - iniconfig==2.1.0
      - jinja2==3.1.6
      - kiwisolver==1.4.7
      - markupsafe==3.0.2
      - matplotlib==3.9.4
      - numpy==2.0.2
      - packaging==24.2
      - pillow==11.1.0
      - pluggy==1.5.0
      - pygments==2.19.1
      - pyparsing==3.2.3
      - pytest==8.3.5
      - python-dateutil==2.9.0.post0
      - requests==2.32.3
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==7.4.7
      - sphinx-rtd-theme==0.4.3
      - sphinxcontrib-applehelp==2.0.0
      - sphinxcontrib-devhelp==2.0.0
      - sphinxcontrib-htmlhelp==2.1.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==2.0.0
      - sphinxcontrib-serializinghtml==2.0.0
      - tomli==2.2.1
      - urllib3==2.3.0
      - zipp==3.21.0
prefix: /opt/conda/envs/RayTracing

raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testLoadWrongFileContent
raytracing/tests/testsRays.py::TestRays::testAppend raytracing/tests/testsRays.py::TestRays::testAppendInvalidInput raytracing/tests/testsRays.py::TestRays::testCountRays raytracing/tests/testsRays.py::TestRays::testDisplayProgress raytracing/tests/testsRays.py::TestRays::testDisplayProgressNothing raytracing/tests/testsRays.py::TestRays::testDisplayProgressSmallerProgressLog raytracing/tests/testsRays.py::TestRays::testRayAnglesHistAlreadyComputed raytracing/tests/testsRays.py::TestRays::testRayAnglesHistogram raytracing/tests/testsRays.py::TestRays::testRayCountHist raytracing/tests/testsRays.py::TestRays::testRayCountHistAlreadyComputed raytracing/tests/testsRays.py::TestRays::testRayCountHistogram raytracing/tests/testsRays.py::TestRays::testRays raytracing/tests/testsRays.py::TestRays::testRaysGetRay raytracing/tests/testsRays.py::TestRays::testRaysInitDifferentInputs raytracing/tests/testsRays.py::TestRays::testRaysIterations raytracing/tests/testsRays.py::TestRays::testRaysLen raytracing/tests/testsRays.py::TestRays::testThetaValues raytracing/tests/testsRays.py::TestRays::testYValues raytracing/tests/testsRays.py::TestRays::testYValuesNotNone raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testLoad raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testLoadFileDoesntExists raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testSaveHugeFile raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testSaveInEmptyFile raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testSaveInFileNotEmpty raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testSaveThenLoad raytracing/tests/testsRays.py::TestRaysSaveAndLoad::testSaveThenLoadHugeFile
raytracing/rays.py
raytracing/rays.py