Skip to content

Commit c2ace5e

Browse files
committed
repo_apkv3: move arbitrary limits to the top of the file
1 parent c8264f9 commit c2ace5e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

ext/repo_apkv3.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
#define ADB_MAX_SIZE 0x10000000
2929

30+
#define MAX_STR_SIZE 0x1000000
31+
#define MAX_ARR_CNT 0x1000000
32+
3033

3134
/* low level */
3235

@@ -93,7 +96,7 @@ adb_arr(const unsigned char *adb, size_t adblen, unsigned int v)
9396
if (v + 4 > adblen)
9497
return 0;
9598
cnt = adb_u32(adb + v);
96-
if (cnt == 0 || cnt >= 0x1000000 || v + 4 * cnt > adblen)
99+
if (cnt == 0 || cnt >= MAX_ARR_CNT || v + 4 * cnt > adblen)
97100
return 0;
98101
return cnt;
99102
}
@@ -114,15 +117,15 @@ adb_poolid(const unsigned char *adb, size_t adblen, unsigned int v, Pool *pool)
114117
{
115118
size_t blobl;
116119
const unsigned char *blob = adb_blob(adb, adblen, v, &blobl);
117-
return blob && blobl < 0x1000000 ? pool_strn2id(pool, (const char *)blob, (unsigned int)blobl, 1) : 0;
120+
return blob && blobl < MAX_STR_SIZE ? pool_strn2id(pool, (const char *)blob, (unsigned int)blobl, 1) : 0;
118121
}
119122

120123
static void
121124
adb_setstr(const unsigned char *adb, size_t adblen, unsigned int v, Repodata *data, Id p, Id key)
122125
{
123126
size_t blobl;
124127
const unsigned char *blob = adb_blob(adb, adblen, v, &blobl);
125-
if (blob && blobl < 0x1000000)
128+
if (blob && blobl < MAX_STR_SIZE)
126129
{
127130
char *space = pool_alloctmpspace(data->repo->pool, blobl + 1);
128131
memcpy(space, blob, blobl);

0 commit comments

Comments
 (0)