File: test_corrupt_files.py

package info (click to toggle)
python-pyelftools 0.32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,964 kB
  • sloc: python: 15,903; ansic: 298; asm: 86; makefile: 24; cpp: 18; sh: 4
file content (28 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Test that elftools does not fail to load corrupted ELF files
"""
import unittest
import os

from elftools.elf.elffile import ELFFile
from elftools.common.exceptions import ELFParseError


class TestCorruptFile(unittest.TestCase):
    def test_elffile_init(self):
        """ Test that ELFFile does not crash when parsing an ELF file with corrupt e_shoff and/or e_shnum
        """
        filepath = os.path.join('test', 'testfiles_for_unittests', 'corrupt_sh.elf')
        with open(filepath, 'rb') as f:
            elf = None

            try:
                elf = ELFFile(f)
            except ELFParseError:
                pass

            self.assertIsInstance(elf, ELFFile, "ELFFile initialization should have detected the out of bounds read")


if __name__ == '__main__':
    unittest.main()