From 31d721301cd410079355e4ab2a46864d57818ce5 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 9 Jan 2020 07:29:00 -0800 Subject: [PATCH] getdeps: dyndeps: gracefully handle empty files Summary: Don't error out if we can't read the ELF/MACH-O header; just treat it is not an object. Reviewed By: chadaustin, simpkins Differential Revision: D19253434 fbshipit-source-id: c5ecc7f0bc7a20e2611b7e2ff754355155f095da --- build/fbcode_builder/getdeps/dyndeps.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build/fbcode_builder/getdeps/dyndeps.py b/build/fbcode_builder/getdeps/dyndeps.py index 47ff13766..abc02e7e9 100644 --- a/build/fbcode_builder/getdeps/dyndeps.py +++ b/build/fbcode_builder/getdeps/dyndeps.py @@ -251,7 +251,10 @@ class MachDeps(DepBase): with open(objfile, "rb") as f: # mach stores the magic number in native endianness, # so unpack as native here and compare - magic = unpack("I", f.read(4))[0] + header = f.read(4) + if len(header) != 4: + return False + magic = unpack("I", header)[0] return magic == MACH_MAGIC def list_dynamic_deps(self, objfile):