Skip to content

Commit 98d0f68

Browse files
committed
APA: enforce maximum partition size limit of 1GB in delete operations
1 parent 6f7812f commit 98d0f68

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

iop/hdd/libapa/src/apa.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ apa_cache_t *apaDeleteFixPrev(apa_cache_t *clink, int *err)
257257
u32 saved_next = clink->header->next;
258258
u32 saved_length = clink->header->length;
259259
u32 tmp;
260+
// TODO: switch to HDDDevices.partitionMaxSize
261+
u32 maxsize = 0x1FFFFF; // 1Gb
260262

261263
while (header->start) {
262264
if (!(clink2 = apaCacheGetHeader(device, header->prev, APA_IO_MODE_READ, err))) {
@@ -265,6 +267,11 @@ apa_cache_t *apaDeleteFixPrev(apa_cache_t *clink, int *err)
265267
}
266268
header = clink2->header;
267269
tmp = header->length + length;
270+
// Check if the new size is larger than the maximum allowed size per APA specs
271+
if (tmp > maxsize) {
272+
apaCacheFree(clink2);
273+
break;
274+
}
268275
if (header->type != 0) {
269276
apaCacheFree(clink2);
270277
break;
@@ -302,6 +309,8 @@ apa_cache_t *apaDeleteFixNext(apa_cache_t *clink, int *err)
302309
u32 lnext = header->next;
303310
u32 device = clink->device;
304311
u32 tmp;
312+
// TODO: switch to HDDDevices.partitionMaxSize
313+
u32 maxsize = 0x1FFFFF; // 1Gb
305314

306315
while (lnext != 0) {
307316
apa_cache_t *clink1;
@@ -312,6 +321,11 @@ apa_cache_t *apaDeleteFixNext(apa_cache_t *clink, int *err)
312321
}
313322
header = clink1->header;
314323
tmp = header->length + length;
324+
// Check if the new size is larger than the maximum allowed size per APA specs
325+
if (tmp > maxsize) {
326+
apaCacheFree(clink1);
327+
break;
328+
}
315329
if (header->type != 0) {
316330
apaCacheFree(clink1);
317331
break;

0 commit comments

Comments
 (0)