ANDROID: Fix negative stack write in sgdisk
A maliciously formatted USB or SD Card device when inserted into an Android device could crash sgdisk. This crash occurs because sgdisk does does not validate the number of cyclic partitions, which leads to an integer underflow ultimately causing a negative indexed stack write.
Fix this by making sure the number of partitions don't go negative.
After the fix, sgdisk detects the broken GPT and partitions it correctly
Test: before fix, sgdisk crashed when USB with malicious GPT was inserted
Test: after fix, sgdisk didn't crash
Test: went through the "formatting" wizard with a malicious GPT and sgdisk successfully reformatted it to vfat
(cherry picked from commit 28ba37956b338e4d5c58f7d8c43c4153f057d482)
1 file changed