Repository: angr/angr

Issue:
CFGFast IndexError: list index out of range
### Description

When running CFGFast on the qedit.dll windows dll (sha256 sum `637bcaf3e43560048d2395a0f539bae19576eaec32fbd5effc6b377ccad411e8  x/disk/Windows/System32/qedit.dll` )
an IndexError ocurrs.

### Steps to reproduce the bug

Using the angr docker image from angr-dev. Windows qedit.dll from the windows developer VM image.
Running the CFGFast results in the error, no special options or handling.

```
(angr) angr@e8292749c96b:/data$ python3
Python 3.8.10 (default, Nov 22 2023, 10:22:35) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import angr
>>> p = angr.Project("x/disk/Windows/System32/qedit.dll", load_options={'auto_load_libs': False})
>>> cfg = p.analyses.CFGFast()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/angr/angr-dev/angr/angr/analyses/analysis.py", line 216, in __call__
    r = w(*args, **kwargs)
  File "/home/angr/angr-dev/angr/angr/analyses/analysis.py", line 201, in wrapper
    oself.__init__(*args, **kwargs)
  File "/home/angr/angr-dev/angr/angr/analyses/cfg/cfg_fast.py", line 844, in __init__
    self._analyze()
  File "/home/angr/angr-dev/angr/angr/analyses/forward_analysis/forward_analysis.py", line 254, in _analyze
    self._post_analysis()
  File "/home/angr/angr-dev/angr/angr/analyses/cfg/cfg_fast.py", line 1648, in _post_analysis
    self._rename_common_functions_and_symbols()
  File "/home/angr/angr-dev/angr/angr/analyses/cfg/cfg_fast.py", line 1714, in _rename_common_functions_and_symbols
    if not security_check_cookie_found and is_function_security_check_cookie(
  File "/home/angr/angr-dev/angr/angr/utils/funcid.py", line 16, in is_function_security_check_cookie
    ins0 = block.capstone.insns[0]
IndexError: list index out of range
>>> 
(angr) angr@e8292749c96b:/data$ sha256sum x/disk/Windows/System32/qedit.dll
637bcaf3e43560048d2395a0f539bae19576eaec32fbd5effc6b377ccad411e8  x/disk/Windows/System32/qedit.dll
```

### Environment

```
(angr) angr@e8292749c96b:/data$ python -m angr.misc.bug_report
angr environment report
=============================
Date: 2024-03-29 15:07:31.842875
Running in virtual environment at /home/angr/.virtualenvs/angr
/home/angr/angr-dev/angr/angr/misc/bug_report.py:88: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources  # pylint:disable=import-outside-toplevel
Platform: linux-x86_64
Python version: 3.8.10 (default, Nov 22 2023, 10:22:35) 
[GCC 9.4.0]
######## angr #########
Python found it in /home/angr/angr-dev/angr/angr/__init__.py
Pip version angr 9.2.97.dev0
Git info:
	Current commit 5239e415474656d14bc87f13ecb1874d8ac9c6cc from branch master
	Checked out from remote origin: https://github.com/angr/angr
######## ailment #########
Python found it in /home/angr/angr-dev/ailment/ailment/__init__.py
Pip version ailment 9.2.97.dev0
Git info:
	Current commit 612da5118ec2884db51b8ea311b721b42816a42a from branch master
	Checked out from remote origin: https://github.com/angr/ailment
######## cle #########
Python found it in /home/angr/angr-dev/cle/cle/__init__.py
Pip version cle 9.2.97.dev0
Git info:
	Current commit b83b9a4d935791080fbfccfa596e5dc017fb41db from branch master
	Checked out from remote origin: https://github.com/angr/cle
######## pyvex #########
Python found it in /home/angr/angr-dev/pyvex/pyvex/__init__.py
Pip version pyvex 9.2.97.dev0
Git info:
	Current commit 95dbfc03236bd9aa50fbd5136316797ec53d9a13 from branch master
	Checked out from remote origin: https://github.com/angr/pyvex
######## claripy #########
Python found it in /home/angr/angr-dev/claripy/claripy/__init__.py
Pip version claripy 9.2.97.dev0
Git info:
	Current commit 567b9be70b2bc9fbdebdb0e30aeea46c5849cf50 from branch master
	Checked out from remote origin: https://github.com/angr/claripy
######## archinfo #########
Python found it in /home/angr/angr-dev/archinfo/archinfo/__init__.py
Pip version archinfo 9.2.97.dev0
Git info:
	Current commit 61a592848b3a8026d16965711f132901ba886c77 from branch master
	Checked out from remote origin: https://github.com/angr/archinfo
######## z3 #########
Python found it in /home/angr/.virtualenvs/angr/lib/python3.8/site-packages/z3/__init__.py
Pip version z3-solver 4.10.2.0
Couldn't find git info
######## unicorn #########
Python found it in /home/angr/.virtualenvs/angr/lib/python3.8/site-packages/unicorn/__init__.py
Pip version unicorn 2.0.1.post1
Couldn't find git info
######### Native Module Info ##########
angr: <CDLL '/home/angr/angr-dev/angr/angr/state_plugins/../lib/angr_native.so', handle 2c3eaf0 at 0x7f82afdc3850>
unicorn: <CDLL '/home/angr/.virtualenvs/angr/lib/python3.8/site-packages/unicorn/lib/libunicorn.so.2', handle 26a5110 at 0x7f82b36d38b0>
pyvex: <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7f82b437aa00>
z3: <CDLL '/home/angr/.virtualenvs/angr/lib/python3.8/site-packages/z3/lib/libz3.so', handle 2338760 at 0x7f82b623cfd0>
```

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/angr/utils/funcid.py b/angr/utils/funcid.py
--- a/angr/utils/funcid.py
+++ b/angr/utils/funcid.py
@@ -13,6 +13,8 @@ def is_function_security_check_cookie(func, project, security_cookie_addr: int)
     block = project.factory.block(func.addr)
     if block.instructions != 2:
         return False
+    if not block.capstone.insns or len(block.capstone.insns) != 2:
+        return False
     ins0 = block.capstone.insns[0]
     if (
         ins0.mnemonic == "cmp"
@@ -57,6 +59,8 @@ def is_function_security_init_cookie(func: "Function", project, security_cookie_
         block = project.factory.block(node_addr, size=node_size)
         if not block.instructions:
             continue
+        if not block.capstone.insns:
+            continue
         last_insn = block.capstone.insns[-1]
         if (
             last_insn.mnemonic == "mov"
@@ -78,6 +82,8 @@ def is_function_security_init_cookie_win8(func: "Function", project, security_co
     block = project.factory.block(func.addr)
     if block.instructions != 3:
         return False
+    if not block.capstone.insns or len(block.capstone.insns) != 3:
+        return False
     ins0 = block.capstone.insns[0]
     if (
         ins0.mnemonic == "mov"


Test patch: