summaryrefslogtreecommitdiffstats
path: root/meta/recipes-multimedia/libtiff/files
diff options
context:
space:
mode:
authorTudor Florea <tudor.florea@enea.com>2015-10-09 20:59:03 (GMT)
committerTudor Florea <tudor.florea@enea.com>2015-10-09 20:59:03 (GMT)
commit972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch)
tree97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /meta/recipes-multimedia/libtiff/files
downloadpoky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/recipes-multimedia/libtiff/files')
-rw-r--r--meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1960.patch151
-rw-r--r--meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1961.patch786
-rw-r--r--meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4231.patch44
-rw-r--r--meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4232.patch15
-rw-r--r--meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4243.patch40
-rw-r--r--meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4244.patch19
-rw-r--r--meta/recipes-multimedia/libtiff/files/libtool2.patch19
-rw-r--r--meta/recipes-multimedia/libtiff/files/tiff-CVE-2012-4564.patch99
8 files changed, 1173 insertions, 0 deletions
diff --git a/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1960.patch b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1960.patch
new file mode 100644
index 0000000..e4348f1
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1960.patch
@@ -0,0 +1,151 @@
1This patch comes from: http://pkgs.fedoraproject.org/cgit/libtiff.git/plain/libtiff-CVE-2013-1960.patch
2
3Upstream-Status: Pending
4
5Signed-off-by: Ming Liu <ming.liu@windriver.com>
6
7diff -Naur a/tools/tiff2pdf.c b/tools/tiff2pdf.c
8--- a/tools/tiff2pdf.c 2012-07-25 22:56:43.000000000 -0400
9+++ b/tools/tiff2pdf.c 2013-05-02 12:04:49.057090227 -0400
10@@ -3341,33 +3341,56 @@
11 uint32 height){
12
13 tsize_t i=0;
14- uint16 ri =0;
15- uint16 v_samp=1;
16- uint16 h_samp=1;
17- int j=0;
18-
19- i++;
20-
21- while(i<(*striplength)){
22+
23+ while (i < *striplength) {
24+ tsize_t datalen;
25+ uint16 ri;
26+ uint16 v_samp;
27+ uint16 h_samp;
28+ int j;
29+ int ncomp;
30+
31+ /* marker header: one or more FFs */
32+ if (strip[i] != 0xff)
33+ return(0);
34+ i++;
35+ while (i < *striplength && strip[i] == 0xff)
36+ i++;
37+ if (i >= *striplength)
38+ return(0);
39+ /* SOI is the only pre-SOS marker without a length word */
40+ if (strip[i] == 0xd8)
41+ datalen = 0;
42+ else {
43+ if ((*striplength - i) <= 2)
44+ return(0);
45+ datalen = (strip[i+1] << 8) | strip[i+2];
46+ if (datalen < 2 || datalen >= (*striplength - i))
47+ return(0);
48+ }
49 switch( strip[i] ){
50- case 0xd8:
51- /* SOI - start of image */
52+ case 0xd8: /* SOI - start of image */
53 _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), 2);
54 *bufferoffset+=2;
55- i+=2;
56 break;
57- case 0xc0:
58- case 0xc1:
59- case 0xc3:
60- case 0xc9:
61- case 0xca:
62+ case 0xc0: /* SOF0 */
63+ case 0xc1: /* SOF1 */
64+ case 0xc3: /* SOF3 */
65+ case 0xc9: /* SOF9 */
66+ case 0xca: /* SOF10 */
67 if(no==0){
68- _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2);
69- for(j=0;j<buffer[*bufferoffset+9];j++){
70- if( (buffer[*bufferoffset+11+(2*j)]>>4) > h_samp)
71- h_samp = (buffer[*bufferoffset+11+(2*j)]>>4);
72- if( (buffer[*bufferoffset+11+(2*j)] & 0x0f) > v_samp)
73- v_samp = (buffer[*bufferoffset+11+(2*j)] & 0x0f);
74+ _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2);
75+ ncomp = buffer[*bufferoffset+9];
76+ if (ncomp < 1 || ncomp > 4)
77+ return(0);
78+ v_samp=1;
79+ h_samp=1;
80+ for(j=0;j<ncomp;j++){
81+ uint16 samp = buffer[*bufferoffset+11+(3*j)];
82+ if( (samp>>4) > h_samp)
83+ h_samp = (samp>>4);
84+ if( (samp & 0x0f) > v_samp)
85+ v_samp = (samp & 0x0f);
86 }
87 v_samp*=8;
88 h_samp*=8;
89@@ -3381,45 +3404,43 @@
90 (unsigned char) ((height>>8) & 0xff);
91 buffer[*bufferoffset+6]=
92 (unsigned char) (height & 0xff);
93- *bufferoffset+=strip[i+2]+2;
94- i+=strip[i+2]+2;
95-
96+ *bufferoffset+=datalen+2;
97+ /* insert a DRI marker */
98 buffer[(*bufferoffset)++]=0xff;
99 buffer[(*bufferoffset)++]=0xdd;
100 buffer[(*bufferoffset)++]=0x00;
101 buffer[(*bufferoffset)++]=0x04;
102 buffer[(*bufferoffset)++]=(ri >> 8) & 0xff;
103 buffer[(*bufferoffset)++]= ri & 0xff;
104- } else {
105- i+=strip[i+2]+2;
106 }
107 break;
108- case 0xc4:
109- case 0xdb:
110- _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2);
111- *bufferoffset+=strip[i+2]+2;
112- i+=strip[i+2]+2;
113+ case 0xc4: /* DHT */
114+ case 0xdb: /* DQT */
115+ _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2);
116+ *bufferoffset+=datalen+2;
117 break;
118- case 0xda:
119+ case 0xda: /* SOS */
120 if(no==0){
121- _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2);
122- *bufferoffset+=strip[i+2]+2;
123- i+=strip[i+2]+2;
124+ _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2);
125+ *bufferoffset+=datalen+2;
126 } else {
127 buffer[(*bufferoffset)++]=0xff;
128 buffer[(*bufferoffset)++]=
129 (unsigned char)(0xd0 | ((no-1)%8));
130- i+=strip[i+2]+2;
131 }
132- _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), (*striplength)-i-1);
133- *bufferoffset+=(*striplength)-i-1;
134+ i += datalen + 1;
135+ /* copy remainder of strip */
136+ _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i]), *striplength - i);
137+ *bufferoffset+= *striplength - i;
138 return(1);
139 default:
140- i+=strip[i+2]+2;
141+ /* ignore any other marker */
142+ break;
143 }
144+ i += datalen + 1;
145 }
146-
147
148+ /* failed to find SOS marker */
149 return(0);
150 }
151 #endif
diff --git a/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1961.patch b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1961.patch
new file mode 100644
index 0000000..fc4adb5
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-1961.patch
@@ -0,0 +1,786 @@
1libtiff: fix CVE-2013-1961.
2
3Upstream-Status: Backported
4
5Issue Description: CVE-2013-1961
6Stack-based buffer overflow in the t2p_write_pdf_page function in tiff2pdf
7in libtiff before 4.0.3 allows remote attackers to cause a denial of service
8(application crash) via a crafted image length and resolution in a TIFF image file.
9
10Fix Description: Replace sprintf with snprintf
11
12Signed-off-by: Priyanka Shobhan <priyanka_shobhan@mentor.com>
13---
14
15diff --git a/contrib/dbs/xtiff/xtiff.c b/contrib/dbs/xtiff/xtiff.c
16index 2634030..97e4ffe 100644
17--- a/contrib/dbs/xtiff/xtiff.c
18+++ b/contrib/dbs/xtiff/xtiff.c
19@@ -512,9 +512,9 @@ SetNameLabel()
20 Arg args[1];
21
22 if (tfMultiPage)
23- sprintf(buffer, "%s - page %d", fileName, tfDirectory);
24+ snprintf(buffer, sizeof(buffer), "%s - page %d", fileName, tfDirectory);
25 else
26- strcpy(buffer, fileName);
27+ snprintf(buffer, sizeof(buffer), "%s", fileName);
28 XtSetArg(args[0], XtNlabel, buffer);
29 XtSetValues(labelWidget, args, 1);
30 }
31diff --git a/libtiff/tif_codec.c b/libtiff/tif_codec.c
32index e201667..703e87d 100644
33--- a/libtiff/tif_codec.c
34+++ b/libtiff/tif_codec.c
35@@ -108,7 +108,8 @@ _notConfigured(TIFF* tif)
36 const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
37 char compression_code[20];
38
39- sprintf( compression_code, "%d", tif->tif_dir.td_compression );
40+ snprintf(compression_code, sizeof(compression_code), "%d",
41+ tif->tif_dir.td_compression );
42 TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
43 "%s compression support is not configured",
44 c ? c->name : compression_code );
45diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c
46index d319931..4dae5e5 100644
47--- a/libtiff/tif_dirinfo.c
48+++ b/libtiff/tif_dirinfo.c
49@@ -711,7 +711,7 @@ _TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type)
50 * note that this name is a special sign to TIFFClose() and
51 * _TIFFSetupFields() to free the field
52 */
53- sprintf(fld->field_name, "Tag %d", (int) tag);
54+ snprintf(fld->field_name, 32, "Tag %d", (int) tag);
55
56 return fld;
57 }
58diff --git a/tools/rgb2ycbcr.c b/tools/rgb2ycbcr.c
59index 162aac1..a3eeb03 100644
60--- a/tools/rgb2ycbcr.c
61+++ b/tools/rgb2ycbcr.c
62@@ -332,7 +332,8 @@ tiffcvt(TIFF* in, TIFF* out)
63 TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
64 { char buf[2048];
65 char *cp = strrchr(TIFFFileName(in), '/');
66- sprintf(buf, "YCbCr conversion of %s", cp ? cp+1 : TIFFFileName(in));
67+ snprintf(buf, sizeof(buf), "YCbCr conversion of %s",
68+ cp ? cp+1 : TIFFFileName(in));
69 TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, buf);
70 }
71 TIFFSetField(out, TIFFTAG_SOFTWARE, TIFFGetVersion());
72diff --git a/tools/tiff2bw.c b/tools/tiff2bw.c
73index bda754a..7ffaca0 100644
74--- a/tools/tiff2bw.c
75+++ b/tools/tiff2bw.c
76@@ -205,7 +205,7 @@ main(int argc, char* argv[])
77 }
78 }
79 TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
80- sprintf(thing, "B&W version of %s", argv[optind]);
81+ snprintf(thing, sizeof(thing), "B&W version of %s", argv[optind]);
82 TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, thing);
83 TIFFSetField(out, TIFFTAG_SOFTWARE, "tiff2bw");
84 outbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
85diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c
86index 356328c..957fd9f 100644
87--- a/tools/tiff2pdf.c
88+++ b/tools/tiff2pdf.c
89@@ -3609,7 +3609,9 @@ tsize_t t2p_write_pdf_header(T2P* t2p, TIFF* output){
90 char buffer[16];
91 int buflen=0;
92
93- buflen=sprintf(buffer, "%%PDF-%u.%u ", t2p->pdf_majorversion&0xff, t2p->pdf_minorversion&0xff);
94+ buflen = snprintf(buffer, sizeof(buffer), "%%PDF-%u.%u ",
95+ t2p->pdf_majorversion&0xff,
96+ t2p->pdf_minorversion&0xff);
97 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
98 written += t2pWriteFile(output, (tdata_t)"\n%\342\343\317\323\n", 7);
99
100@@ -3623,10 +3625,10 @@ tsize_t t2p_write_pdf_header(T2P* t2p, TIFF* output){
101 tsize_t t2p_write_pdf_obj_start(uint32 number, TIFF* output){
102
103 tsize_t written=0;
104- char buffer[16];
105+ char buffer[32];
106 int buflen=0;
107
108- buflen=sprintf(buffer, "%lu", (unsigned long)number);
109+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)number);
110 written += t2pWriteFile(output, (tdata_t) buffer, buflen );
111 written += t2pWriteFile(output, (tdata_t) " 0 obj\n", 7);
112
113@@ -3665,13 +3667,13 @@ tsize_t t2p_write_pdf_name(unsigned char* name, TIFF* output){
114 written += t2pWriteFile(output, (tdata_t) "/", 1);
115 for (i=0;i<namelen;i++){
116 if ( ((unsigned char)name[i]) < 0x21){
117- sprintf(buffer, "#%.2X", name[i]);
118+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
119 buffer[sizeof(buffer) - 1] = '\0';
120 written += t2pWriteFile(output, (tdata_t) buffer, 3);
121 nextchar=1;
122 }
123 if ( ((unsigned char)name[i]) > 0x7E){
124- sprintf(buffer, "#%.2X", name[i]);
125+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
126 buffer[sizeof(buffer) - 1] = '\0';
127 written += t2pWriteFile(output, (tdata_t) buffer, 3);
128 nextchar=1;
129@@ -3679,57 +3681,57 @@ tsize_t t2p_write_pdf_name(unsigned char* name, TIFF* output){
130 if (nextchar==0){
131 switch (name[i]){
132 case 0x23:
133- sprintf(buffer, "#%.2X", name[i]);
134+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
135 buffer[sizeof(buffer) - 1] = '\0';
136 written += t2pWriteFile(output, (tdata_t) buffer, 3);
137 break;
138 case 0x25:
139- sprintf(buffer, "#%.2X", name[i]);
140+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
141 buffer[sizeof(buffer) - 1] = '\0';
142 written += t2pWriteFile(output, (tdata_t) buffer, 3);
143 break;
144 case 0x28:
145- sprintf(buffer, "#%.2X", name[i]);
146+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
147 buffer[sizeof(buffer) - 1] = '\0';
148 written += t2pWriteFile(output, (tdata_t) buffer, 3);
149 break;
150 case 0x29:
151- sprintf(buffer, "#%.2X", name[i]);
152+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
153 buffer[sizeof(buffer) - 1] = '\0';
154 written += t2pWriteFile(output, (tdata_t) buffer, 3);
155 break;
156 case 0x2F:
157- sprintf(buffer, "#%.2X", name[i]);
158+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
159 buffer[sizeof(buffer) - 1] = '\0';
160 written += t2pWriteFile(output, (tdata_t) buffer, 3);
161 break;
162 case 0x3C:
163- sprintf(buffer, "#%.2X", name[i]);
164+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
165 buffer[sizeof(buffer) - 1] = '\0';
166 written += t2pWriteFile(output, (tdata_t) buffer, 3);
167 break;
168 case 0x3E:
169- sprintf(buffer, "#%.2X", name[i]);
170+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
171 buffer[sizeof(buffer) - 1] = '\0';
172 written += t2pWriteFile(output, (tdata_t) buffer, 3);
173 break;
174 case 0x5B:
175- sprintf(buffer, "#%.2X", name[i]);
176+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
177 buffer[sizeof(buffer) - 1] = '\0';
178 written += t2pWriteFile(output, (tdata_t) buffer, 3);
179 break;
180 case 0x5D:
181- sprintf(buffer, "#%.2X", name[i]);
182+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
183 buffer[sizeof(buffer) - 1] = '\0';
184 written += t2pWriteFile(output, (tdata_t) buffer, 3);
185 break;
186 case 0x7B:
187- sprintf(buffer, "#%.2X", name[i]);
188+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
189 buffer[sizeof(buffer) - 1] = '\0';
190 written += t2pWriteFile(output, (tdata_t) buffer, 3);
191 break;
192 case 0x7D:
193- sprintf(buffer, "#%.2X", name[i]);
194+ snprintf(buffer, sizeof(buffer), "#%.2X", name[i]);
195 buffer[sizeof(buffer) - 1] = '\0';
196 written += t2pWriteFile(output, (tdata_t) buffer, 3);
197 break;
198@@ -3844,14 +3846,14 @@ tsize_t t2p_write_pdf_stream_end(TIFF* output){
199 tsize_t t2p_write_pdf_stream_dict(tsize_t len, uint32 number, TIFF* output){
200
201 tsize_t written=0;
202- char buffer[16];
203+ char buffer[32];
204 int buflen=0;
205
206 written += t2pWriteFile(output, (tdata_t) "/Length ", 8);
207 if(len!=0){
208 written += t2p_write_pdf_stream_length(len, output);
209 } else {
210- buflen=sprintf(buffer, "%lu", (unsigned long)number);
211+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)number);
212 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
213 written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6);
214 }
215@@ -3892,10 +3894,10 @@ tsize_t t2p_write_pdf_stream_dict_end(TIFF* output){
216 tsize_t t2p_write_pdf_stream_length(tsize_t len, TIFF* output){
217
218 tsize_t written=0;
219- char buffer[16];
220+ char buffer[32];
221 int buflen=0;
222
223- buflen=sprintf(buffer, "%lu", (unsigned long)len);
224+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)len);
225 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
226 written += t2pWriteFile(output, (tdata_t) "\n", 1);
227
228@@ -3909,7 +3911,7 @@ tsize_t t2p_write_pdf_stream_length(tsize_t len, TIFF* output){
229 tsize_t t2p_write_pdf_catalog(T2P* t2p, TIFF* output)
230 {
231 tsize_t written = 0;
232- char buffer[16];
233+ char buffer[32];
234 int buflen = 0;
235
236 written += t2pWriteFile(output,
237@@ -3948,7 +3950,6 @@ tsize_t t2p_write_pdf_info(T2P* t2p, TIFF* input, TIFF* output)
238 written += t2p_write_pdf_string(t2p->pdf_datetime, output);
239 }
240 written += t2pWriteFile(output, (tdata_t) "\n/Producer ", 11);
241- _TIFFmemset((tdata_t)buffer, 0x00, sizeof(buffer));
242 snprintf(buffer, sizeof(buffer), "libtiff / tiff2pdf - %d", TIFFLIB_VERSION);
243 written += t2p_write_pdf_string(buffer, output);
244 written += t2pWriteFile(output, (tdata_t) "\n", 1);
245@@ -4089,7 +4090,7 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output)
246 {
247 tsize_t written=0;
248 tdir_t i=0;
249- char buffer[16];
250+ char buffer[32];
251 int buflen=0;
252
253 int page=0;
254@@ -4097,7 +4098,7 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output)
255 (tdata_t) "<< \n/Type /Pages \n/Kids [ ", 26);
256 page = t2p->pdf_pages+1;
257 for (i=0;i<t2p->tiff_pagecount;i++){
258- buflen=sprintf(buffer, "%d", page);
259+ buflen=snprintf(buffer, sizeof(buffer), "%d", page);
260 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
261 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
262 if ( ((i+1)%8)==0 ) {
263@@ -4112,8 +4113,7 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output)
264 }
265 }
266 written += t2pWriteFile(output, (tdata_t) "] \n/Count ", 10);
267- _TIFFmemset(buffer, 0x00, 16);
268- buflen=sprintf(buffer, "%d", t2p->tiff_pagecount);
269+ buflen=snprintf(buffer, sizeof(buffer), "%d", t2p->tiff_pagecount);
270 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
271 written += t2pWriteFile(output, (tdata_t) " \n>> \n", 6);
272
273@@ -4128,28 +4128,28 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){
274
275 unsigned int i=0;
276 tsize_t written=0;
277- char buffer[16];
278+ char buffer[256];
279 int buflen=0;
280
281 written += t2pWriteFile(output, (tdata_t) "<<\n/Type /Page \n/Parent ", 24);
282- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_pages);
283+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_pages);
284 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
285 written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6);
286 written += t2pWriteFile(output, (tdata_t) "/MediaBox [", 11);
287- buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.x1);
288+ buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.x1);
289 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
290 written += t2pWriteFile(output, (tdata_t) " ", 1);
291- buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.y1);
292+ buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.y1);
293 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
294 written += t2pWriteFile(output, (tdata_t) " ", 1);
295- buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.x2);
296+ buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.x2);
297 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
298 written += t2pWriteFile(output, (tdata_t) " ", 1);
299- buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.y2);
300+ buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.y2);
301 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
302 written += t2pWriteFile(output, (tdata_t) "] \n", 3);
303 written += t2pWriteFile(output, (tdata_t) "/Contents ", 10);
304- buflen=sprintf(buffer, "%lu", (unsigned long)(object + 1));
305+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(object + 1));
306 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
307 written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6);
308 written += t2pWriteFile(output, (tdata_t) "/Resources << \n", 15);
309@@ -4157,15 +4157,13 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){
310 written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12);
311 for(i=0;i<t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount;i++){
312 written += t2pWriteFile(output, (tdata_t) "/Im", 3);
313- buflen = sprintf(buffer, "%u", t2p->pdf_page+1);
314+ buflen = snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1);
315 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
316 written += t2pWriteFile(output, (tdata_t) "_", 1);
317- buflen = sprintf(buffer, "%u", i+1);
318+ buflen = snprintf(buffer, sizeof(buffer), "%u", i+1);
319 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
320 written += t2pWriteFile(output, (tdata_t) " ", 1);
321- buflen = sprintf(
322- buffer,
323- "%lu",
324+ buflen = snprintf(buffer, sizeof(buffer), "%lu",
325 (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra));
326 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
327 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
328@@ -4177,12 +4175,10 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){
329 } else {
330 written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12);
331 written += t2pWriteFile(output, (tdata_t) "/Im", 3);
332- buflen = sprintf(buffer, "%u", t2p->pdf_page+1);
333+ buflen = snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1);
334 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
335 written += t2pWriteFile(output, (tdata_t) " ", 1);
336- buflen = sprintf(
337- buffer,
338- "%lu",
339+ buflen = snprintf(buffer, sizeof(buffer), "%lu",
340 (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra));
341 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
342 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
343@@ -4191,9 +4187,7 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){
344 if(t2p->tiff_transferfunctioncount != 0) {
345 written += t2pWriteFile(output, (tdata_t) "/ExtGState <<", 13);
346 t2pWriteFile(output, (tdata_t) "/GS1 ", 5);
347- buflen = sprintf(
348- buffer,
349- "%lu",
350+ buflen = snprintf(buffer, sizeof(buffer), "%lu",
351 (unsigned long)(object + 3));
352 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
353 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
354@@ -4566,7 +4560,7 @@ tsize_t t2p_write_pdf_page_content_stream(T2P* t2p, TIFF* output){
355 if(t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount>0){
356 for(i=0;i<t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount; i++){
357 box=t2p->tiff_tiles[t2p->pdf_page].tiles_tiles[i].tile_box;
358- buflen=sprintf(buffer,
359+ buflen=snprintf(buffer, sizeof(buffer),
360 "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d_%ld Do Q\n",
361 t2p->tiff_transferfunctioncount?"/GS1 gs ":"",
362 box.mat[0],
363@@ -4581,7 +4575,7 @@ tsize_t t2p_write_pdf_page_content_stream(T2P* t2p, TIFF* output){
364 }
365 } else {
366 box=t2p->pdf_imagebox;
367- buflen=sprintf(buffer,
368+ buflen=snprintf(buffer, sizeof(buffer),
369 "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d Do Q\n",
370 t2p->tiff_transferfunctioncount?"/GS1 gs ":"",
371 box.mat[0],
372@@ -4606,59 +4600,48 @@ tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t tile,
373 TIFF* output){
374
375 tsize_t written=0;
376- char buffer[16];
377+ char buffer[32];
378 int buflen=0;
379
380 written += t2p_write_pdf_stream_dict(0, t2p->pdf_xrefcount+1, output);
381 written += t2pWriteFile(output,
382 (tdata_t) "/Type /XObject \n/Subtype /Image \n/Name /Im",
383 42);
384- buflen=sprintf(buffer, "%u", t2p->pdf_page+1);
385+ buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1);
386 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
387 if(tile != 0){
388 written += t2pWriteFile(output, (tdata_t) "_", 1);
389- buflen=sprintf(buffer, "%lu", (unsigned long)tile);
390+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)tile);
391 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
392 }
393 written += t2pWriteFile(output, (tdata_t) "\n/Width ", 8);
394- _TIFFmemset((tdata_t)buffer, 0x00, 16);
395 if(tile==0){
396- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_width);
397+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->tiff_width);
398 } else {
399 if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)!=0){
400- buflen=sprintf(
401- buffer,
402- "%lu",
403+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
404 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth);
405 } else {
406- buflen=sprintf(
407- buffer,
408- "%lu",
409+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
410 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth);
411 }
412 }
413 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
414 written += t2pWriteFile(output, (tdata_t) "\n/Height ", 9);
415- _TIFFmemset((tdata_t)buffer, 0x00, 16);
416 if(tile==0){
417- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_length);
418+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->tiff_length);
419 } else {
420 if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)!=0){
421- buflen=sprintf(
422- buffer,
423- "%lu",
424+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
425 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);
426 } else {
427- buflen=sprintf(
428- buffer,
429- "%lu",
430+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
431 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);
432 }
433 }
434 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
435 written += t2pWriteFile(output, (tdata_t) "\n/BitsPerComponent ", 19);
436- _TIFFmemset((tdata_t)buffer, 0x00, 16);
437- buflen=sprintf(buffer, "%u", t2p->tiff_bitspersample);
438+ buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_bitspersample);
439 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
440 written += t2pWriteFile(output, (tdata_t) "\n/ColorSpace ", 13);
441 written += t2p_write_pdf_xobject_cs(t2p, output);
442@@ -4702,11 +4685,10 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){
443 t2p->pdf_colorspace ^= T2P_CS_PALETTE;
444 written += t2p_write_pdf_xobject_cs(t2p, output);
445 t2p->pdf_colorspace |= T2P_CS_PALETTE;
446- buflen=sprintf(buffer, "%u", (0x0001 << t2p->tiff_bitspersample)-1 );
447+ buflen=snprintf(buffer, sizeof(buffer), "%u", (0x0001 << t2p->tiff_bitspersample)-1 );
448 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
449 written += t2pWriteFile(output, (tdata_t) " ", 1);
450- _TIFFmemset(buffer, 0x00, 16);
451- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_palettecs );
452+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_palettecs );
453 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
454 written += t2pWriteFile(output, (tdata_t) " 0 R ]\n", 7);
455 return(written);
456@@ -4740,10 +4722,10 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){
457 X_W /= Y_W;
458 Z_W /= Y_W;
459 Y_W = 1.0F;
460- buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W);
461+ buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W);
462 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
463 written += t2pWriteFile(output, (tdata_t) "/Range ", 7);
464- buflen=sprintf(buffer, "[%d %d %d %d] \n",
465+ buflen=snprintf(buffer, sizeof(buffer), "[%d %d %d %d] \n",
466 t2p->pdf_labrange[0],
467 t2p->pdf_labrange[1],
468 t2p->pdf_labrange[2],
469@@ -4759,26 +4741,26 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){
470 tsize_t t2p_write_pdf_transfer(T2P* t2p, TIFF* output){
471
472 tsize_t written=0;
473- char buffer[16];
474+ char buffer[32];
475 int buflen=0;
476
477 written += t2pWriteFile(output, (tdata_t) "<< /Type /ExtGState \n/TR ", 25);
478 if(t2p->tiff_transferfunctioncount == 1){
479- buflen=sprintf(buffer, "%lu",
480+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
481 (unsigned long)(t2p->pdf_xrefcount + 1));
482 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
483 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
484 } else {
485 written += t2pWriteFile(output, (tdata_t) "[ ", 2);
486- buflen=sprintf(buffer, "%lu",
487+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
488 (unsigned long)(t2p->pdf_xrefcount + 1));
489 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
490 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
491- buflen=sprintf(buffer, "%lu",
492+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
493 (unsigned long)(t2p->pdf_xrefcount + 2));
494 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
495 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
496- buflen=sprintf(buffer, "%lu",
497+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
498 (unsigned long)(t2p->pdf_xrefcount + 3));
499 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
500 written += t2pWriteFile(output, (tdata_t) " 0 R ", 5);
501@@ -4800,7 +4782,7 @@ tsize_t t2p_write_pdf_transfer_dict(T2P* t2p, TIFF* output, uint16 i){
502 written += t2pWriteFile(output, (tdata_t) "/FunctionType 0 \n", 17);
503 written += t2pWriteFile(output, (tdata_t) "/Domain [0.0 1.0] \n", 19);
504 written += t2pWriteFile(output, (tdata_t) "/Range [0.0 1.0] \n", 18);
505- buflen=sprintf(buffer, "/Size [%u] \n", (1<<t2p->tiff_bitspersample));
506+ buflen=snprintf(buffer, sizeof(buffer), "/Size [%u] \n", (1<<t2p->tiff_bitspersample));
507 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
508 written += t2pWriteFile(output, (tdata_t) "/BitsPerSample 16 \n", 19);
509 written += t2p_write_pdf_stream_dict(((tsize_t)1)<<(t2p->tiff_bitspersample+1), 0, output);
510@@ -4827,7 +4809,7 @@ tsize_t t2p_write_pdf_transfer_stream(T2P* t2p, TIFF* output, uint16 i){
511 tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){
512
513 tsize_t written=0;
514- char buffer[128];
515+ char buffer[256];
516 int buflen=0;
517
518 float X_W=0.0;
519@@ -4895,16 +4877,16 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){
520 written += t2pWriteFile(output, (tdata_t) "<< \n", 4);
521 if(t2p->pdf_colorspace & T2P_CS_CALGRAY){
522 written += t2pWriteFile(output, (tdata_t) "/WhitePoint ", 12);
523- buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W);
524+ buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W);
525 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
526 written += t2pWriteFile(output, (tdata_t) "/Gamma 2.2 \n", 12);
527 }
528 if(t2p->pdf_colorspace & T2P_CS_CALRGB){
529 written += t2pWriteFile(output, (tdata_t) "/WhitePoint ", 12);
530- buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W);
531+ buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W);
532 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
533 written += t2pWriteFile(output, (tdata_t) "/Matrix ", 8);
534- buflen=sprintf(buffer, "[%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f] \n",
535+ buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f] \n",
536 X_R, Y_R, Z_R,
537 X_G, Y_G, Z_G,
538 X_B, Y_B, Z_B);
539@@ -4923,11 +4905,11 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){
540 tsize_t t2p_write_pdf_xobject_icccs(T2P* t2p, TIFF* output){
541
542 tsize_t written=0;
543- char buffer[16];
544+ char buffer[32];
545 int buflen=0;
546
547 written += t2pWriteFile(output, (tdata_t) "[/ICCBased ", 11);
548- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_icccs);
549+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_icccs);
550 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
551 written += t2pWriteFile(output, (tdata_t) " 0 R] \n", 7);
552
553@@ -4937,11 +4919,11 @@ tsize_t t2p_write_pdf_xobject_icccs(T2P* t2p, TIFF* output){
554 tsize_t t2p_write_pdf_xobject_icccs_dict(T2P* t2p, TIFF* output){
555
556 tsize_t written=0;
557- char buffer[16];
558+ char buffer[32];
559 int buflen=0;
560
561 written += t2pWriteFile(output, (tdata_t) "/N ", 3);
562- buflen=sprintf(buffer, "%u \n", t2p->tiff_samplesperpixel);
563+ buflen=snprintf(buffer, sizeof(buffer), "%u \n", t2p->tiff_samplesperpixel);
564 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
565 written += t2pWriteFile(output, (tdata_t) "/Alternate ", 11);
566 t2p->pdf_colorspace ^= T2P_CS_ICCBASED;
567@@ -5006,7 +4988,7 @@ tsize_t t2p_write_pdf_xobject_decode(T2P* t2p, TIFF* output){
568 tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output){
569
570 tsize_t written=0;
571- char buffer[16];
572+ char buffer[32];
573 int buflen=0;
574
575 if(t2p->pdf_compression==T2P_COMPRESS_NONE){
576@@ -5021,41 +5003,33 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output
577 written += t2pWriteFile(output, (tdata_t) "<< /K -1 ", 9);
578 if(tile==0){
579 written += t2pWriteFile(output, (tdata_t) "/Columns ", 9);
580- buflen=sprintf(buffer, "%lu",
581+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
582 (unsigned long)t2p->tiff_width);
583 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
584 written += t2pWriteFile(output, (tdata_t) " /Rows ", 7);
585- buflen=sprintf(buffer, "%lu",
586+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
587 (unsigned long)t2p->tiff_length);
588 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
589 } else {
590 if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){
591 written += t2pWriteFile(output, (tdata_t) "/Columns ", 9);
592- buflen=sprintf(
593- buffer,
594- "%lu",
595+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
596 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth);
597 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
598 } else {
599 written += t2pWriteFile(output, (tdata_t) "/Columns ", 9);
600- buflen=sprintf(
601- buffer,
602- "%lu",
603+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
604 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth);
605 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
606 }
607 if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){
608 written += t2pWriteFile(output, (tdata_t) " /Rows ", 7);
609- buflen=sprintf(
610- buffer,
611- "%lu",
612+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
613 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);
614 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
615 } else {
616 written += t2pWriteFile(output, (tdata_t) " /Rows ", 7);
617- buflen=sprintf(
618- buffer,
619- "%lu",
620+ buflen=snprintf(buffer, sizeof(buffer), "%lu",
621 (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);
622 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
623 }
624@@ -5082,21 +5056,17 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output
625 if(t2p->pdf_compressionquality%100){
626 written += t2pWriteFile(output, (tdata_t) "/DecodeParms ", 13);
627 written += t2pWriteFile(output, (tdata_t) "<< /Predictor ", 14);
628- _TIFFmemset(buffer, 0x00, 16);
629- buflen=sprintf(buffer, "%u", t2p->pdf_compressionquality%100);
630+ buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_compressionquality%100);
631 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
632 written += t2pWriteFile(output, (tdata_t) " /Columns ", 10);
633- _TIFFmemset(buffer, 0x00, 16);
634- buflen = sprintf(buffer, "%lu",
635+ buflen = snprintf(buffer, sizeof(buffer), "%lu",
636 (unsigned long)t2p->tiff_width);
637 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
638 written += t2pWriteFile(output, (tdata_t) " /Colors ", 9);
639- _TIFFmemset(buffer, 0x00, 16);
640- buflen=sprintf(buffer, "%u", t2p->tiff_samplesperpixel);
641+ buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_samplesperpixel);
642 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
643 written += t2pWriteFile(output, (tdata_t) " /BitsPerComponent ", 19);
644- _TIFFmemset(buffer, 0x00, 16);
645- buflen=sprintf(buffer, "%u", t2p->tiff_bitspersample);
646+ buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_bitspersample);
647 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
648 written += t2pWriteFile(output, (tdata_t) ">>\n", 3);
649 }
650@@ -5116,16 +5086,16 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output
651 tsize_t t2p_write_pdf_xreftable(T2P* t2p, TIFF* output){
652
653 tsize_t written=0;
654- char buffer[21];
655+ char buffer[64];
656 int buflen=0;
657 uint32 i=0;
658
659 written += t2pWriteFile(output, (tdata_t) "xref\n0 ", 7);
660- buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 1));
661+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(t2p->pdf_xrefcount + 1));
662 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
663 written += t2pWriteFile(output, (tdata_t) " \n0000000000 65535 f \n", 22);
664 for (i=0;i<t2p->pdf_xrefcount;i++){
665- sprintf(buffer, "%.10lu 00000 n \n",
666+ snprintf(buffer, sizeof(buffer), "%.10lu 00000 n \n",
667 (unsigned long)t2p->pdf_xrefoffsets[i]);
668 written += t2pWriteFile(output, (tdata_t) buffer, 20);
669 }
670@@ -5149,17 +5119,14 @@ tsize_t t2p_write_pdf_trailer(T2P* t2p, TIFF* output)
671 snprintf(t2p->pdf_fileid + i, 9, "%.8X", rand());
672
673 written += t2pWriteFile(output, (tdata_t) "trailer\n<<\n/Size ", 17);
674- buflen = sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount+1));
675+ buflen = snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(t2p->pdf_xrefcount+1));
676 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
677- _TIFFmemset(buffer, 0x00, 32);
678 written += t2pWriteFile(output, (tdata_t) "\n/Root ", 7);
679- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_catalog);
680+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_catalog);
681 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
682- _TIFFmemset(buffer, 0x00, 32);
683 written += t2pWriteFile(output, (tdata_t) " 0 R \n/Info ", 12);
684- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_info);
685+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_info);
686 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
687- _TIFFmemset(buffer, 0x00, 32);
688 written += t2pWriteFile(output, (tdata_t) " 0 R \n/ID[<", 11);
689 written += t2pWriteFile(output, (tdata_t) t2p->pdf_fileid,
690 sizeof(t2p->pdf_fileid) - 1);
691@@ -5167,9 +5134,8 @@ tsize_t t2p_write_pdf_trailer(T2P* t2p, TIFF* output)
692 written += t2pWriteFile(output, (tdata_t) t2p->pdf_fileid,
693 sizeof(t2p->pdf_fileid) - 1);
694 written += t2pWriteFile(output, (tdata_t) ">]\n>>\nstartxref\n", 16);
695- buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_startxref);
696+ buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_startxref);
697 written += t2pWriteFile(output, (tdata_t) buffer, buflen);
698- _TIFFmemset(buffer, 0x00, 32);
699 written += t2pWriteFile(output, (tdata_t) "\n%%EOF\n", 7);
700
701 return(written);
702diff --git a/tools/tiff2ps.c b/tools/tiff2ps.c
703index 3330750..7a9a816 100644
704--- a/tools/tiff2ps.c
705+++ b/tools/tiff2ps.c
706@@ -1789,8 +1789,8 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h)
707 imageOp = "imagemask";
708
709 (void)strcpy(im_x, "0");
710- (void)sprintf(im_y, "%lu", (long) h);
711- (void)sprintf(im_h, "%lu", (long) h);
712+ (void)snprintf(im_y, sizeof(im_y), "%lu", (long) h);
713+ (void)snprintf(im_h, sizeof(im_h), "%lu", (long) h);
714 tile_width = w;
715 tile_height = h;
716 if (TIFFIsTiled(tif)) {
717@@ -1811,7 +1811,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h)
718 }
719 if (tile_height < h) {
720 fputs("/im_y 0 def\n", fd);
721- (void)sprintf(im_y, "%lu im_y sub", (unsigned long) h);
722+ (void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h);
723 }
724 } else {
725 repeat_count = tf_numberstrips;
726@@ -1823,7 +1823,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h)
727 fprintf(fd, "/im_h %lu def\n",
728 (unsigned long) tile_height);
729 (void)strcpy(im_h, "im_h");
730- (void)sprintf(im_y, "%lu im_y sub", (unsigned long) h);
731+ (void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h);
732 }
733 }
734
735diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
736index 9cd5d86..a2443aa 100644
737--- a/tools/tiffcrop.c
738+++ b/tools/tiffcrop.c
739@@ -2077,7 +2077,7 @@ update_output_file (TIFF **tiffout, char *mode, int autoindex,
740 return 1;
741 }
742
743- sprintf (filenum, "-%03d%s", findex, export_ext);
744+ snprintf(filenum, sizeof(filenum), "-%03d%s", findex, export_ext);
745 filenum[14] = '\0';
746 strncat (exportname, filenum, 15);
747 }
748@@ -2230,8 +2230,8 @@ main(int argc, char* argv[])
749
750 /* dump.infilename is guaranteed to be NUL termimated and have 20 bytes
751 fewer than PATH_MAX */
752- memset (temp_filename, '\0', PATH_MAX + 1);
753- sprintf (temp_filename, "%s-read-%03d.%s", dump.infilename, dump_images,
754+ snprintf(temp_filename, sizeof(temp_filename), "%s-read-%03d.%s",
755+ dump.infilename, dump_images,
756 (dump.format == DUMP_TEXT) ? "txt" : "raw");
757 if ((dump.infile = fopen(temp_filename, dump.mode)) == NULL)
758 {
759@@ -2249,8 +2249,8 @@ main(int argc, char* argv[])
760
761 /* dump.outfilename is guaranteed to be NUL termimated and have 20 bytes
762 fewer than PATH_MAX */
763- memset (temp_filename, '\0', PATH_MAX + 1);
764- sprintf (temp_filename, "%s-write-%03d.%s", dump.outfilename, dump_images,
765+ snprintf(temp_filename, sizeof(temp_filename), "%s-write-%03d.%s",
766+ dump.outfilename, dump_images,
767 (dump.format == DUMP_TEXT) ? "txt" : "raw");
768 if ((dump.outfile = fopen(temp_filename, dump.mode)) == NULL)
769 {
770diff --git a/tools/tiffdither.c b/tools/tiffdither.c
771index f2f0f20..4308946 100644
772--- a/tools/tiffdither.c
773+++ b/tools/tiffdither.c
774@@ -260,7 +260,7 @@ main(int argc, char* argv[])
775 TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);
776 else
777 CopyField(TIFFTAG_FILLORDER, shortv);
778- sprintf(thing, "Dithered B&W version of %s", argv[optind]);
779+ snprintf(thing, sizeof(thing), "Dithered B&W version of %s", argv[optind]);
780 TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, thing);
781 CopyField(TIFFTAG_PHOTOMETRIC, shortv);
782 CopyField(TIFFTAG_ORIENTATION, shortv);
783--
7841.8.3.rc3
785
786
diff --git a/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4231.patch b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4231.patch
new file mode 100644
index 0000000..d8d4e96
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4231.patch
@@ -0,0 +1,44 @@
1Upstream-Status: Backport
2
3Multiple buffer overflows in libtiff before 4.0.3 allow remote attackers
4to cause a denial of service (out-of-bounds write) via a crafted (1)
5extension block in a GIF image or (2) GIF raster image to
6tools/gif2tiff.c or (3) a long filename for a TIFF image to
7tools/rgb2ycbcr.c. NOTE: vectors 1 and 3 are disputed by Red Hat, which
8states that the input cannot exceed the allocated buffer size.
9
10http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-4231Multiple
11buffer overflows in libtiff before 4.0.3 allow remote attackers to cause
12a denial of service (out-of-bounds write) via a crafted (1) extension
13block in a GIF image or (2) GIF raster image to tools/gif2tiff.c or (3)
14a long filename for a TIFF image to tools/rgb2ycbcr.c. NOTE: vectors 1
15and 3 are disputed by Red Hat, which states that the input cannot exceed
16the allocated buffer size.
17
18http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-4231
19
20Signed-off-by: Yue Tao <Yue.Tao@windriver.com>
21
22Index: tools/gif2tiff.c
23===================================================================
24RCS file: /cvs/maptools/cvsroot/libtiff/tools/gif2tiff.c,v
25retrieving revision 1.12
26retrieving revision 1.13
27diff -u -r1.12 -r1.13
28--- a/tools/gif2tiff.c 15 Dec 2010 00:22:44 -0000 1.12
29+++ b/tools/gif2tiff.c 14 Aug 2013 05:18:53 -0000 1.13
30@@ -1,4 +1,4 @@
31-/* $Id: gif2tiff.c,v 1.12 2010-12-15 00:22:44 faxguy Exp $ */
32+/* $Id: gif2tiff.c,v 1.13 2013-08-14 05:18:53 fwarmerdam Exp $ */
33
34 /*
35 * Copyright (c) 1990-1997 Sam Leffler
36@@ -333,6 +333,8 @@
37 int status = 1;
38
39 datasize = getc(infile);
40+ if (datasize > 12)
41+ return 0;
42 clear = 1 << datasize;
43 eoi = clear + 1;
44 avail = clear + 2;
diff --git a/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4232.patch b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4232.patch
new file mode 100644
index 0000000..9ebf8f9a
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4232.patch
@@ -0,0 +1,15 @@
1This patch comes from: http://bugzilla.maptools.org/attachment.cgi?id=513&action=diff
2
3Upstream-Status: Pending
4
5Signed-off-by: Baogen shang <baogen.shang@windriver.com>
6--- a/tools/tiff2pdf.c 2013-10-21 10:36:38.214170346 +0800
7+++ b/tools/tiff2pdf.c 2013-10-21 10:38:58.246170329 +0800
8@@ -2387,6 +2387,7 @@
9 TIFFFileName(input));
10 t2p->t2p_error = T2P_ERR_ERROR;
11 _TIFFfree(buffer);
12+ return(0);
13 } else {
14 buffer=samplebuffer;
15 t2p->tiff_datasize *= t2p->tiff_samplesperpixel;
diff --git a/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4243.patch b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4243.patch
new file mode 100644
index 0000000..642a117
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4243.patch
@@ -0,0 +1,40 @@
1This patch comes from: http://bugzilla.maptools.org/attachment.cgi?id=518&action=diff#tools/gif2tiff.c_sec2
2
3Upstream-Status: Pending
4
5Signed-off-by: Baogen shang <baogen.shang@windriver.com>
6--- a/tools/gif2tiff.c 2013-10-14 17:08:43.966239709 +0800
7+++ b/tools/gif2tiff.c 2013-10-14 17:18:22.994239638 +0800
8@@ -280,6 +280,10 @@
9 fprintf(stderr, "no colormap present for image\n");
10 return (0);
11 }
12+ if (width == 0 || height == 0) {
13+ fprintf(stderr, "Invalid value of width or height\n");
14+ return(0);
15+ }
16 if ((raster = (unsigned char*) _TIFFmalloc(width*height+EXTRAFUDGE)) == NULL) {
17 fprintf(stderr, "not enough memory for image\n");
18 return (0);
19@@ -397,6 +401,10 @@
20 return 1;
21 }
22
23+ if (*fill >= raster + width*height) {
24+ fprintf(stderr, "raster full before eoi code\n");
25+ return 0;
26+ }
27 if (oldcode == -1) {
28 *(*fill)++ = suffix[code];
29 firstchar = oldcode = code;
30@@ -428,6 +436,10 @@
31 }
32 oldcode = incode;
33 do {
34+ if (*fill >= raster + width*height) {
35+ fprintf(stderr, "raster full before eoi code\n");
36+ return 0;
37+ }
38 *(*fill)++ = *--stackp;
39 } while (stackp > stack);
40 return 1;
diff --git a/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4244.patch b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4244.patch
new file mode 100644
index 0000000..1a66830
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/libtiff-CVE-2013-4244.patch
@@ -0,0 +1,19 @@
1This patch comes from: https://github.com/vadz/libtiff/commit/ce6841d9e41d621ba23cf18b190ee6a23b2cc833
2
3Upstream-Status: Backport
4
5Signed-off-by: Baogen shang <baogen.shang@windriver.com>
6--- a/tools/gif2tiff.c 2013-12-17 16:46:02.160814995 +0800
7+++ b/tools/gif2tiff.c 2013-12-17 16:52:25.140814949 +0800
8@@ -406,6 +406,11 @@
9 return 0;
10 }
11 if (oldcode == -1) {
12+ if (code >= clear) {
13+ fprintf(stderr, "bad input: code=%d is larger than clear=%d\n",code, clear);
14+ return 0;
15+ }
16+
17 *(*fill)++ = suffix[code];
18 firstchar = oldcode = code;
19 return 1;
diff --git a/meta/recipes-multimedia/libtiff/files/libtool2.patch b/meta/recipes-multimedia/libtiff/files/libtool2.patch
new file mode 100644
index 0000000..457202e
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/libtool2.patch
@@ -0,0 +1,19 @@
1Upstream-Status: Inappropriate [configuration]
2
3---
4 configure.ac | 2 +-
5 1 file changed, 1 insertion(+), 1 deletion(-)
6
7Index: tiff-3.9.5/configure.ac
8===================================================================
9--- tiff-3.9.5.orig/configure.ac
10+++ tiff-3.9.5/configure.ac
11@@ -27,7 +27,7 @@ dnl Process this file with autoconf to p
12 AC_PREREQ(2.64)
13 AC_INIT([LibTIFF Software],[3.9.5],[tiff@lists.maptools.org],[tiff])
14 AC_CONFIG_AUX_DIR(config)
15-AC_CONFIG_MACRO_DIR(m4)
16+dnl AC_CONFIG_MACRO_DIR(m4)
17 AC_LANG(C)
18
19 dnl Compute the canonical host (run-time) system type variable
diff --git a/meta/recipes-multimedia/libtiff/files/tiff-CVE-2012-4564.patch b/meta/recipes-multimedia/libtiff/files/tiff-CVE-2012-4564.patch
new file mode 100644
index 0000000..2364979
--- /dev/null
+++ b/meta/recipes-multimedia/libtiff/files/tiff-CVE-2012-4564.patch
@@ -0,0 +1,99 @@
1Upstream-Status: Backport
2
3Signed-off-by: Yue Tao <Yue.Tao@windriver.com>
4Signed-off-by: Wenzong Fan <wenzong.fan@windriver.com>
5
6Index: tools/ppm2tiff.c
7===================================================================
8RCS file: /cvs/maptools/cvsroot/libtiff/tools/ppm2tiff.c,v
9retrieving revision 1.16
10retrieving revision 1.18
11diff -u -r1.16 -r1.18
12--- a/tools/ppm2tiff.c 10 Apr 2010 19:22:34 -0000 1.16
13+++ b/tools/ppm2tiff.c 10 Dec 2012 18:19:11 -0000 1.18
14@@ -1,4 +1,4 @@
15-/* $Id: ppm2tiff.c,v 1.16 2010-04-10 19:22:34 bfriesen Exp $ */
16+/* $Id: ppm2tiff.c,v 1.18 2012-12-10 18:19:11 tgl Exp $ */
17
18 /*
19 * Copyright (c) 1991-1997 Sam Leffler
20@@ -72,6 +72,17 @@
21 exit(-2);
22 }
23
24+static tmsize_t
25+multiply_ms(tmsize_t m1, tmsize_t m2)
26+{
27+ tmsize_t bytes = m1 * m2;
28+
29+ if (m1 && bytes / m1 != m2)
30+ bytes = 0;
31+
32+ return bytes;
33+}
34+
35 int
36 main(int argc, char* argv[])
37 {
38@@ -79,7 +90,7 @@
39 uint32 rowsperstrip = (uint32) -1;
40 double resolution = -1;
41 unsigned char *buf = NULL;
42- tsize_t linebytes = 0;
43+ tmsize_t linebytes = 0;
44 uint16 spp = 1;
45 uint16 bpp = 8;
46 TIFF *out;
47@@ -89,6 +100,7 @@
48 int c;
49 extern int optind;
50 extern char* optarg;
51+ tmsize_t scanline_size;
52
53 if (argc < 2) {
54 fprintf(stderr, "%s: Too few arguments\n", argv[0]);
55@@ -221,7 +233,8 @@
56 }
57 switch (bpp) {
58 case 1:
59- linebytes = (spp * w + (8 - 1)) / 8;
60+ /* if round-up overflows, result will be zero, OK */
61+ linebytes = (multiply_ms(spp, w) + (8 - 1)) / 8;
62 if (rowsperstrip == (uint32) -1) {
63 TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h);
64 } else {
65@@ -230,15 +243,31 @@
66 }
67 break;
68 case 8:
69- linebytes = spp * w;
70+ linebytes = multiply_ms(spp, w);
71 TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
72 TIFFDefaultStripSize(out, rowsperstrip));
73 break;
74 }
75- if (TIFFScanlineSize(out) > linebytes)
76+ if (linebytes == 0) {
77+ fprintf(stderr, "%s: scanline size overflow\n", infile);
78+ (void) TIFFClose(out);
79+ exit(-2);
80+ }
81+ scanline_size = TIFFScanlineSize(out);
82+ if (scanline_size == 0) {
83+ /* overflow - TIFFScanlineSize already printed a message */
84+ (void) TIFFClose(out);
85+ exit(-2);
86+ }
87+ if (scanline_size < linebytes)
88 buf = (unsigned char *)_TIFFmalloc(linebytes);
89 else
90- buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
91+ buf = (unsigned char *)_TIFFmalloc(scanline_size);
92+ if (buf == NULL) {
93+ fprintf(stderr, "%s: Not enough memory\n", infile);
94+ (void) TIFFClose(out);
95+ exit(-2);
96+ }
97 if (resolution > 0) {
98 TIFFSetField(out, TIFFTAG_XRESOLUTION, resolution);
99 TIFFSetField(out, TIFFTAG_YRESOLUTION, resolution);