if ((byte_offset + header->get_sector_size()) > buf_len)
return;
- while ((count - (fat_sector_curr_cnt * max_secchain_cnt)) < (max_secchain_cnt))
+ while ((count - (fat_sector_curr_cnt * max_secchain_cnt)) < (max_secchain_cnt) and count < fat_list_len)
{
if (!header->get_byte_order())
fat_list[count] = LETOHL_UNALIGNED(buf);
count++;
buf += 4;
}
+ if (count >= fat_list_len) {
+ break;
+ }
fat_sector_curr_cnt++;
if (fat_sector_curr_cnt < MAX_DIFAT_SECTORS)
current_sector = header->get_difat_array(fat_sector_curr_cnt);
buf += byte_offset;
- while ((count - (minfat_curr_cnt * max_secchain_cnt)) < max_secchain_cnt)
+ while ((count - (minfat_curr_cnt * max_secchain_cnt)) < max_secchain_cnt and count < mini_fat_list_len)
{
if (!header->get_byte_order())
mini_fat_list[count] = LETOHL_UNALIGNED(buf);
count++;
buf += 4;
}
+ if (count >= mini_fat_list_len) {
+ break;
+ }
minfat_curr_cnt++;
int32_t next_sector = get_next_fat_sector(current_sector);
if (next_sector > INVALID_SECTOR)