1 commit 433cc73f9df08a1435b4d07a7bd3eed20f0c3dcd
2 Author: Francois Gouget <fgouget@codeweavers.com>
3 Date: Tue Dec 20 19:39:41 2011 +0100
5 bfd: Refuse to create an invalid archive when an archive element is too big.
7 The archive format stores element sizes as a 10 character string and thus cannot handle anything 10GB or more.
9 diff --git a/bfd/archive.c b/bfd/archive.c
10 index 5c5b3d4..05aba6c 100644
13 @@ -179,13 +179,18 @@ _bfd_ar_spacepad (char *p, size_t n, const char *fmt, long val)
19 _bfd_ar_sizepad (char *p, size_t n, bfd_size_type size)
23 snprintf (buf, sizeof (buf), "%-10" BFD_VMA_FMT "u", size);
27 + bfd_set_error(bfd_error_file_too_big);
33 @@ -193,6 +198,7 @@ _bfd_ar_sizepad (char *p, size_t n, bfd_size_type size)
41 @@ -1786,8 +1792,9 @@ _bfd_bsd44_write_ar_hdr (bfd *archive, bfd *abfd)
43 BFD_ASSERT (padded_len == arch_eltdata (abfd)->extra_size);
45 - _bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
46 - arch_eltdata (abfd)->parsed_size + padded_len);
47 + if (!_bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
48 + arch_eltdata (abfd)->parsed_size + padded_len))
51 if (bfd_bwrite (hdr, sizeof (*hdr), archive) != sizeof (*hdr))
53 @@ -1907,8 +1914,8 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member)
55 _bfd_ar_spacepad (hdr->ar_mode, sizeof (hdr->ar_mode), "%-8lo",
57 - _bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
59 + if (!_bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size), status.st_size))
61 memcpy (hdr->ar_fmag, ARFMAG, 2);
62 ared->parsed_size = status.st_size;
63 ared->arch_header = (char *) hdr;
64 @@ -2148,8 +2155,9 @@ _bfd_write_archive_contents (bfd *arch)
65 memset (&hdr, ' ', sizeof (struct ar_hdr));
66 memcpy (hdr.ar_name, ename, strlen (ename));
67 /* Round size up to even number in archive header. */
68 - _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
69 - (elength + 1) & ~(bfd_size_type) 1);
70 + if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
71 + (elength + 1) & ~(bfd_size_type) 1))
73 memcpy (hdr.ar_fmag, ARFMAG, 2);
74 if ((bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
75 != sizeof (struct ar_hdr))
76 @@ -2425,7 +2433,8 @@ bsd_write_armap (bfd *arch,
77 bfd_ardata (arch)->armap_timestamp);
78 _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", uid);
79 _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", gid);
80 - _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize);
81 + if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize))
83 memcpy (hdr.ar_fmag, ARFMAG, 2);
84 if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
85 != sizeof (struct ar_hdr))
86 @@ -2580,7 +2589,8 @@ coff_write_armap (bfd *arch,
88 memset (&hdr, ' ', sizeof (struct ar_hdr));
90 - _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize);
91 + if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize))
93 _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
94 ((arch->flags & BFD_DETERMINISTIC_OUTPUT) == 0
96 diff --git a/bfd/archive64.c b/bfd/archive64.c
97 index a906508..bdbda0a 100644
100 @@ -169,8 +169,8 @@ bfd_elf64_archive_write_armap (bfd *arch,
102 memset (&hdr, ' ', sizeof (struct ar_hdr));
103 memcpy (hdr.ar_name, "/SYM64/", strlen ("/SYM64/"));
104 - _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
106 + if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize))
108 _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
110 /* This, at least, is what Intel coff sets the values to.: */
111 diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
112 index 57197ac..a4ba4b6 100644
113 --- a/bfd/libbfd-in.h
114 +++ b/bfd/libbfd-in.h
115 @@ -203,7 +203,7 @@ extern void *_bfd_generic_read_ar_hdr
117 extern void _bfd_ar_spacepad
118 (char *, size_t, const char *, long);
119 -extern void _bfd_ar_sizepad
120 +extern int _bfd_ar_sizepad
121 (char *, size_t, bfd_size_type);
123 extern void *_bfd_generic_read_ar_hdr_mag
124 diff --git a/bfd/libbfd.h b/bfd/libbfd.h
125 index 121e865..7f142d0 100644
128 @@ -208,7 +208,7 @@ extern void *_bfd_generic_read_ar_hdr
130 extern void _bfd_ar_spacepad
131 (char *, size_t, const char *, long);
132 -extern void _bfd_ar_sizepad
133 +extern int _bfd_ar_sizepad
134 (char *, size_t, bfd_size_type);
136 extern void *_bfd_generic_read_ar_hdr_mag