Commit f98c564
Address infinite loops while reading ID3v2 tags. (#48)
The `Buffer.read()` call will infinitely loop if the number of bytes
remaining in the file is less than the requested size. A large number of
`read()` calls in `ID3v2Parser` are at risk of infinitely looping on
malformed files. I'm changing `Buffer` to throw an exception when it
detects there are no more bytes to read from the file.
There is a more egregious case with the potential `Xing` header. The
parser blindly reads 1500 bytes to search for the header, but there is
no guarantee (even in a well-formed file) that there will be 1500 more
bytes remaining to be read. I'm introducing a `readAtMost` method to
`Buffer` which will handle cases where there are fewer than `size` bytes
remaining in the file.
I'm also updating some of the logic which is checking for the start of
the `Xing` header to be safer, checking to ensure that there are enough
bytes remaining to parse the data from this header.
Co-authored-by: Loren Van Spronsen <lorenvs@google.com>1 parent 68b0915 commit f98c564
File tree
4 files changed
+52
-4
lines changed- lib/src
- parsers
- utils
- test/mp3
4 files changed
+52
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
| 249 | + | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
| 258 | + | |
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
11 | 19 | | |
12 | 20 | | |
13 | 21 | | |
| |||
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
20 | 41 | | |
21 | 42 | | |
22 | 43 | | |
| |||
61 | 82 | | |
62 | 83 | | |
63 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
64 | 88 | | |
65 | 89 | | |
66 | 90 | | |
67 | 91 | | |
68 | 92 | | |
69 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
70 | 103 | | |
71 | 104 | | |
72 | 105 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
49 | 63 | | |
0 commit comments