Lekensteyn / lglaf

LG Download Mode utility and documentation
https://lekensteyn.nl/lglaf/
MIT License
137 stars 74 forks source link

Off-by-one error in partition sizing #38

Closed Jookia closed 6 years ago

Jookia commented 6 years ago

The following code in partitions.py:

part_offset = part.first_lba * BLOCK_SIZE
part_size = (part.last_lba - part.first_lba) * BLOCK_SIZE

should be:

part_offset = part.first_lba * BLOCK_SIZE
part_size = (part.last_lba - part.first_lba + 1) * BLOCK_SIZE

Consider having a disk of 20 blocks, and you have a partition that starts at 5 and ends at 10. part_size would end up being 10 - 5, which is 5 blocks. Unfortunately, the partition is actually blocks 5,6,7,8,9,10 , which is 6 blocks!

Without this fix, downloading a partition will drop the last block.

steadfasterX commented 6 years ago

thx for reminding me to submit my PR ;) see PR #40

Jookia commented 6 years ago

This has been fixed for a while. Closing.