diff -rupN --no-dereference binutils-2.40/bfd/elf.c binutils-2.40-new/bfd/elf.c
--- binutils-2.40/bfd/elf.c	2023-04-14 16:12:16.185323541 +0200
+++ binutils-2.40-new/bfd/elf.c	2023-04-14 16:12:27.583371759 +0200
@@ -9048,6 +9048,9 @@ _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;
@@ -9151,6 +9154,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;
