--- binutils.orig/bfd/elf.c	2023-04-17 16:26:08.720347439 +0100
+++ binutils-2.40/bfd/elf.c	2023-04-17 16:28:03.286317601 +0100
@@ -9050,6 +9050,8 @@ _bfd_elf_slurp_version_tables (bfd *abfd
 	  bfd_set_error (bfd_error_file_too_big);
 	  goto error_return_verdef;
 	}
+      if (amt == 0)
+	goto error_return_verdef;
       elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *) bfd_zalloc (abfd, amt);
       if (elf_tdata (abfd)->verdef == NULL)
 	goto error_return_verdef;
@@ -9153,6 +9155,8 @@ _bfd_elf_slurp_version_tables (bfd *abfd
 	  bfd_set_error (bfd_error_file_too_big);
 	  goto error_return;
 	}
+      if (amt == 0)
+	goto error_return;
       elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *) bfd_zalloc (abfd, amt);
       if (elf_tdata (abfd)->verdef == NULL)
 	goto error_return;
