Skip to content

Commit 52dce5e

Browse files
authored
Properly check windres .rsrc section size (#11816)
To prevent "file truncated" errors and resulting bfd_fatal exit, it's necessary to check both section filepos and sections size.
1 parent e6daa20 commit 52dce5e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

projects/binutils/fuzz_windres.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ fuzz_check_coff_rsrc (const char *filename, const char *target)
5151
bfd *abfd;
5252
windres_bfd wrbfd;
5353
asection *sec;
54-
bfd_size_type size;
5554

5655
abfd = bfd_openr (filename, target);
5756
if (abfd == NULL) {
@@ -64,14 +63,16 @@ fuzz_check_coff_rsrc (const char *filename, const char *target)
6463
}
6564

6665
sec = bfd_get_section_by_name (abfd, ".rsrc");
67-
if (sec == NULL) {
66+
if (sec == NULL || sec->size == 0) {
6867
retval = 0;
6968
goto cleanup;
7069
}
7170

7271
set_windres_bfd (&wrbfd, abfd, sec, WR_KIND_BFD);
73-
size = bfd_section_size (sec);
74-
if (size > (bfd_size_type) get_file_size (filename)) {
72+
73+
bfd_size_type filesize = get_file_size (filename);
74+
if ((ufile_ptr) sec->filepos > filesize
75+
|| sec->size > filesize - sec->filepos) {
7576
retval = 0;
7677
goto cleanup;
7778
}

0 commit comments

Comments
 (0)