lemire / simdcomp

A simple C library for compressing lists of integers using binary packing
BSD 3-Clause "New" or "Revised" License
488 stars 53 forks source link

heap-buffer-overflow (detected by LibFuzzer) #21

Closed eeeeYxN closed 6 years ago

eeeeYxN commented 6 years ago

Here is my function LLVMFuzzerTestOneInput : test_input.zip

sizeof in is :  110
0 : 73
1 : 73
2 : 73
3 : 73
4 : 73
5 : 73
6 : 157
7 : 73
8 : 73
9 : 73
10 : 73
11 : 73
12 : 73
13 : 73
14 : 0
15 : 0
16 : 0
17 : 0
18 : 0
19 : 0
20 : 0
21 : 0
22 : 0
23 : 0
24 : 0
25 : 0
26 : 0
27 : 0
28 : 0
29 : 0
30 : 0
31 : 0
32 : 0
33 : 0
34 : 0
35 : 0
36 : 0
37 : 0
38 : 0
39 : 0
40 : 0
41 : 0
42 : 255
43 : 255
44 : 255
45 : 0
46 : 0
47 : 0
48 : 0
49 : 0
50 : 0
51 : 0
52 : 0
53 : 0
54 : 0
55 : 0
56 : 0
57 : 0
58 : 0
59 : 0
60 : 0
61 : 0
62 : 0
63 : 0
64 : 0
65 : 0
66 : 0
67 : 0
68 : 0
69 : 0
70 : 0
71 : 0
72 : 0
73 : 0
74 : 0
75 : 0
76 : 0
77 : 0
78 : 0
79 : 0
80 : 0
81 : 0
82 : 0
83 : 0
84 : 0
85 : 0
86 : 0
87 : 0
88 : 0
89 : 0
90 : 0
91 : 0
92 : 0
93 : 0
94 : 0
95 : 41
96 : 0
97 : 0
98 : 0
99 : 0
100 : 0
101 : 0
102 : 0
103 : 73
104 : 73
105 : 73
106 : 73
107 : 73
108 : 73
109 : 41
packing
unpacking
=================================================================
==2137==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60b000001600 at pc 0x00000068a431 bp 0x7ffe5a401c90 sp 0x7ffe5a401c88
READ of size 16 at 0x60b000001600 thread T0
    #0 0x68a430  (/my/simdcomp/test_input+0x68a430)
    #1 0x54ab28  (/my/simdcomp/test_input+0x54ab28)
    #2 0x42eac7  (/my/simdcomp/test_input+0x42eac7)
    #3 0x439334  (/my/simdcomp/test_input+0x439334)
    #4 0x43a99f  (/my/simdcomp/test_input+0x43a99f)
    #5 0x429d5c  (/my/simdcomp/test_input+0x429d5c)
    #6 0x41cc22  (/my/simdcomp/test_input+0x41cc22)
    #7 0x7f1c2cf39b96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #8 0x41cc99  (/my/simdcomp/test_input+0x41cc99)

0x60b000001600 is located 0 bytes to the right of 112-byte region [0x60b000001590,0x60b000001600)
allocated by thread T0 here:
    #0 0x5121b0  (/my/simdcomp/test_input+0x5121b0)
    #1 0x54aaeb  (/my/simdcomp/test_input+0x54aaeb)
    #2 0x42eac7  (/my/simdcomp/test_input+0x42eac7)
    #3 0x439334  (/my/simdcomp/test_input+0x439334)
    #4 0x43a99f  (/my/simdcomp/test_input+0x43a99f)
    #5 0x429d5c  (/my/simdcomp/test_input+0x429d5c)
    #6 0x41cc22  (/my/simdcomp/test_input+0x41cc22)
    #7 0x7f1c2cf39b96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: heap-buffer-overflow (/my/simdcomp/test_input+0x68a430) 
Shadow bytes around the buggy address:
  0x0c167fff8270: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa
  0x0c167fff8280: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
  0x0c167fff8290: fd fd fd fd fa fa fa fa fa fa fa fa 00 00 00 00
  0x0c167fff82a0: 00 00 00 00 00 00 00 00 00 06 fa fa fa fa fa fa
  0x0c167fff82b0: fa fa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c167fff82c0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff82d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff82f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff8300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c167fff8310: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==2137==ABORTING
MS: 2 InsertByte-InsertRepeatedBytes-; base unit: e327b8bb508e837ff0f4550c4494658769d8262a
0x49,0x49,0x49,0x49,0x49,0x49,0x9d,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x29,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x49,0x49,0x49,0x49,0x49,0x49,0x29,
IIIIII\x9dIIIIIII\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00\x00\x00\x00\x00IIIIII)
artifact_prefix='./'; Test unit written to ./crash-4dc1b47ec0015baf910b70995c37d0b7231129c6
Base64: SUlJSUlJnUlJSUlJSUkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApAAAAAAAAAElJSUlJSSk=
lemire commented 6 years ago

Thank you. In rare cases, we would read (and then discard) extra bytes. The problem should be fixed now. You can check the fix by running the unit tests with a sanitizer. Sadly I do not know how to integrate a unit test in our CI testing framework at the moment.

eeeeYxN commented 6 years ago

Still the same problem...

sizeof in is :  416
0 : 219
1 : 219
2 : 43
3 : 36
4 : 36
5 : 36
6 : 219
7 : 219
8 : 219
9 : 219
10 : 219
11 : 219
12 : 219
13 : 219
14 : 219
15 : 219
16 : 219
17 : 219
18 : 219
19 : 219
20 : 219
21 : 219
22 : 219
23 : 219
24 : 219
25 : 219
26 : 219
27 : 39
28 : 219
29 : 219
30 : 219
31 : 219
32 : 219
33 : 219
34 : 43
35 : 36
36 : 36
37 : 36
38 : 219
39 : 219
40 : 219
41 : 219
42 : 219
43 : 219
44 : 219
45 : 219
46 : 219
47 : 219
48 : 219
49 : 219
50 : 219
51 : 219
52 : 219
53 : 219
54 : 219
55 : 219
56 : 219
57 : 219
58 : 219
59 : 219
60 : 219
61 : 219
62 : 219
63 : 219
64 : 219
65 : 219
66 : 219
67 : 234
68 : 219
69 : 219
70 : 219
71 : 219
72 : 219
73 : 219
74 : 219
75 : 219
76 : 219
77 : 219
78 : 219
79 : 219
80 : 219
81 : 219
82 : 219
83 : 219
84 : 219
85 : 219
86 : 219
87 : 219
88 : 219
89 : 46
90 : 46
91 : 46
92 : 46
93 : 46
94 : 46
95 : 46
96 : 46
97 : 46
98 : 46
99 : 46
100 : 46
101 : 46
102 : 46
103 : 46
104 : 46
105 : 46
106 : 46
107 : 46
108 : 46
109 : 46
110 : 46
111 : 46
112 : 46
113 : 46
114 : 46
115 : 46
116 : 46
117 : 46
118 : 46
119 : 46
120 : 46
121 : 46
122 : 46
123 : 46
124 : 46
125 : 219
126 : 219
127 : 219
128 : 219
129 : 234
130 : 219
131 : 219
132 : 219
133 : 219
134 : 219
135 : 219
136 : 219
137 : 219
138 : 219
139 : 219
140 : 219
141 : 219
142 : 219
143 : 219
144 : 219
145 : 219
146 : 219
147 : 219
148 : 219
149 : 219
150 : 219
151 : 219
152 : 219
153 : 219
154 : 46
155 : 46
156 : 46
157 : 36
158 : 36
159 : 219
160 : 219
161 : 219
162 : 219
163 : 219
164 : 219
165 : 219
166 : 219
167 : 219
168 : 219
169 : 219
170 : 219
171 : 219
172 : 219
173 : 219
174 : 219
175 : 219
176 : 219
177 : 219
178 : 219
179 : 219
180 : 39
181 : 219
182 : 219
183 : 219
184 : 219
185 : 219
186 : 219
187 : 43
188 : 36
189 : 36
190 : 36
191 : 219
192 : 219
193 : 219
194 : 219
195 : 219
196 : 219
197 : 219
198 : 219
199 : 219
200 : 219
201 : 219
202 : 219
203 : 219
204 : 219
205 : 219
206 : 219
207 : 219
208 : 219
209 : 219
210 : 219
211 : 219
212 : 219
213 : 219
214 : 219
215 : 219
216 : 219
217 : 219
218 : 219
219 : 219
220 : 234
221 : 219
222 : 219
223 : 219
224 : 219
225 : 219
226 : 219
227 : 219
228 : 219
229 : 219
230 : 219
231 : 219
232 : 219
233 : 219
234 : 219
235 : 219
236 : 219
237 : 219
238 : 219
239 : 219
240 : 219
241 : 219
242 : 46
243 : 46
244 : 46
245 : 46
246 : 46
247 : 46
248 : 46
249 : 46
250 : 46
251 : 46
252 : 46
253 : 46
254 : 46
255 : 46
256 : 46
257 : 46
258 : 46
259 : 46
260 : 46
261 : 46
262 : 46
263 : 46
264 : 46
265 : 46
266 : 46
267 : 46
268 : 46
269 : 46
270 : 46
271 : 46
272 : 46
273 : 46
274 : 46
275 : 46
276 : 46
277 : 46
278 : 219
279 : 219
280 : 219
281 : 219
282 : 234
283 : 219
284 : 219
285 : 219
286 : 219
287 : 219
288 : 219
289 : 219
290 : 219
291 : 219
292 : 219
293 : 219
294 : 219
295 : 219
296 : 219
297 : 219
298 : 219
299 : 219
300 : 219
301 : 219
302 : 219
303 : 219
304 : 219
305 : 219
306 : 219
307 : 46
308 : 46
309 : 46
310 : 46
311 : 46
312 : 46
313 : 46
314 : 46
315 : 46
316 : 46
317 : 46
318 : 46
319 : 46
320 : 46
321 : 46
322 : 46
323 : 46
324 : 42
325 : 46
326 : 46
327 : 46
328 : 46
329 : 46
330 : 46
331 : 46
332 : 46
333 : 46
334 : 46
335 : 46
336 : 46
337 : 46
338 : 46
339 : 46
340 : 46
341 : 46
342 : 46
343 : 46
344 : 46
345 : 46
346 : 46
347 : 46
348 : 46
349 : 46
350 : 46
351 : 46
352 : 46
353 : 46
354 : 42
355 : 46
356 : 46
357 : 46
358 : 46
359 : 46
360 : 46
361 : 46
362 : 46
363 : 46
364 : 46
365 : 46
366 : 46
367 : 46
368 : 46
369 : 46
370 : 46
371 : 46
372 : 46
373 : 46
374 : 46
375 : 46
376 : 46
377 : 46
378 : 46
379 : 46
380 : 46
381 : 46
382 : 46
383 : 46
384 : 46
385 : 46
386 : 46
387 : 46
388 : 46
389 : 46
390 : 46
391 : 46
392 : 46
393 : 46
394 : 46
395 : 46
396 : 46
397 : 46
398 : 46
399 : 46
400 : 46
401 : 46
402 : 46
403 : 46
404 : 46
405 : 46
406 : 46
407 : 46
408 : 46
409 : 46
410 : 46
411 : 46
412 : 46
413 : 46
414 : 46
415 : 10

==7228==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6140000003e0 at pc 0x0000006ab74b bp 0x7fffa3f90850 sp 0x7fffa3f90848
READ of size 16 at 0x6140000003e0 thread T0
    #0 0x6ab74a  (/my/simdcomp/test_input+0x6ab74a)
    #1 0x6ac36b  (/my/simdcomp/test_input+0x6ac36b)
    #2 0x54aae8  (/my/simdcomp/test_input+0x54aae8)
    #3 0x42ea87  (/my/simdcomp/test_input+0x42ea87)
    #4 0x4392f4  (/my/simdcomp/test_input+0x4392f4)
    #5 0x43a95f  (/my/simdcomp/test_input+0x43a95f)
    #6 0x429d1c  (/my/simdcomp/test_input+0x429d1c)
    #7 0x41cbe2  (/my/simdcomp/test_input+0x41cbe2)
    #8 0x7f169be4fb96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #9 0x41cc59  (/my/simdcomp/test_input+0x41cc59)

0x6140000003e0 is located 0 bytes to the right of 416-byte region [0x614000000240,0x6140000003e0)
allocated by thread T0 here:
    #0 0x512170  (/my/simdcomp/test_input+0x512170)
    #1 0x54aaab  (/my/simdcomp/test_input+0x54aaab)
    #2 0x42ea87  (/my/simdcomp/test_input+0x42ea87)
    #3 0x4392f4  (/my/simdcomp/test_input+0x4392f4)
    #4 0x43a95f  (/my/simdcomp/test_input+0x43a95f)
    #5 0x429d1c  (/my/simdcomp/test_input+0x429d1c)
    #6 0x41cbe2  (/my/simdcomp/test_input+0x41cbe2)
    #7 0x7f169be4fb96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: heap-buffer-overflow (/my/simdcomp/test_input+0x6ab74a) 
Shadow bytes around the buggy address:
  0x0c287fff8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff8030: 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa fa
  0x0c287fff8040: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c287fff8050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff8060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c287fff8070: 00 00 00 00 00 00 00 00 00 00 00 00[fa]fa fa fa
  0x0c287fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff8090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff80a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff80b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==7228==ABORTING
MS: 5 InsertByte-ShuffleBytes-ChangeBit-CopyPart-CopyPart-; base unit: 1076af7d660b69620765a6b95d855b2421a4e922
artifact_prefix='./'; Test unit written to ./crash-683932b0e12a9d248058abab7989b1c9e1b9ba5f
lemire commented 6 years ago

Fixed. Thanks.