Commit 18356db
committed
fix buffer overflow in DiskAccess::read_exact_into
DiskAccess::read_exact_into did not work correctly if current_offset
wasn't aligned to 512 bytes.
For example, if self.current_offset is 3 and len is 1024:
- end_addr will be 3+1024=1027
- start_lba will be 3/512=0
- end_lba (1027-1)=2
read_exact_into would then read 3 (!) sectors with lbas 0, 1, and 2
even though the buffer can only hold 2 sectors (1024 bytes).
To fix this, only allow seeking to the start of a sector.
DiskAccess::read_exact_into works correctly if the offset is a multiple
of the sector size.
There were few uses of DiskAccess::seek that didn't seek to the start
of a sector. All those uses then use DiskAccess::read_exact to read
data at the offset. Unlike DiskAccess::read_exact_into,
DiskAccess::read_exact can already handle non-aligned offsets. To fix
the bad seek calls, we turn read_exact into a combined seek+offset
function that works for non-aligned offsets.1 parent 9a5cf6b commit 18356db
2 files changed
+13
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | | - | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 35 | + | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
256 | 255 | | |
257 | 256 | | |
258 | 257 | | |
259 | | - | |
| 258 | + | |
260 | 259 | | |
261 | 260 | | |
262 | 261 | | |
| |||
286 | 285 | | |
287 | 286 | | |
288 | 287 | | |
289 | | - | |
| 288 | + | |
290 | 289 | | |
291 | 290 | | |
292 | 291 | | |
| |||
476 | 475 | | |
477 | 476 | | |
478 | 477 | | |
479 | | - | |
| 478 | + | |
480 | 479 | | |
481 | 480 | | |
482 | 481 | | |
483 | 482 | | |
484 | 483 | | |
485 | | - | |
486 | | - | |
| 484 | + | |
487 | 485 | | |
488 | 486 | | |
489 | 487 | | |
490 | 488 | | |
491 | 489 | | |
492 | | - | |
493 | | - | |
| 490 | + | |
494 | 491 | | |
495 | 492 | | |
496 | 493 | | |
497 | 494 | | |
498 | 495 | | |
499 | | - | |
500 | | - | |
| 496 | + | |
501 | 497 | | |
502 | 498 | | |
503 | 499 | | |
| |||
0 commit comments