|
29 | 29 |
|
30 | 30 | #define ADB_MAX_SIZE 0x10000000 |
31 | 31 |
|
| 32 | + |
| 33 | +/* low level */ |
| 34 | + |
32 | 35 | static inline unsigned int |
33 | 36 | adb_u32(const unsigned char *p) |
34 | 37 | { |
35 | 38 | return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; |
36 | 39 | } |
37 | 40 |
|
38 | | -static int |
39 | | -adb_read_blk_header(FILE *fp, unsigned long long *sizep) |
40 | | -{ |
41 | | - unsigned char buf[12]; |
42 | | - unsigned int size; |
43 | | - unsigned long long lsize; |
44 | | - if (fread(buf, 4, 1, fp) != 1) |
45 | | - return -1; |
46 | | - size = buf[0] | buf[1] << 8 | buf[2] << 16 | (buf[3] & 0x3f) << 24; |
47 | | - if ((buf[3] & 0xc0) != 0xc0) |
48 | | - { |
49 | | - if (size < 4) |
50 | | - return -1; |
51 | | - *sizep = size - 4; |
52 | | - return (buf[3] & 0xc0) >> 3; |
53 | | - } |
54 | | - if (fread(buf, 12, 1, fp) != 1) |
55 | | - return -1; |
56 | | - lsize = adb_u32(buf + 4); |
57 | | - lsize |= (unsigned long long)adb_u32(buf + 8) << 32; |
58 | | - if (lsize < 16) |
59 | | - return -1; |
60 | | - *sizep = lsize - 16; |
61 | | - return size; |
62 | | -} |
63 | | - |
64 | | -/* low level */ |
65 | | - |
66 | 41 | static const unsigned char * |
67 | 42 | adb_blob(const unsigned char *adb, size_t adblen, unsigned int v, size_t *bloblp) |
68 | 43 | { |
@@ -317,6 +292,34 @@ add_add_idb_pkg(Pool *pool, Repo *repo, Repodata *data, const unsigned char *adb |
317 | 292 | return adb_add_pkg_info(pool, repo, data, adb, adblen, adb_idx(adb, v, cnt, 1), flags); |
318 | 293 | } |
319 | 294 |
|
| 295 | +/* file reading */ |
| 296 | + |
| 297 | +static int |
| 298 | +adb_read_blk_header(FILE *fp, unsigned long long *sizep) |
| 299 | +{ |
| 300 | + unsigned char buf[12]; |
| 301 | + unsigned int size; |
| 302 | + unsigned long long lsize; |
| 303 | + if (fread(buf, 4, 1, fp) != 1) |
| 304 | + return -1; |
| 305 | + size = buf[0] | buf[1] << 8 | buf[2] << 16 | (buf[3] & 0x3f) << 24; |
| 306 | + if ((buf[3] & 0xc0) != 0xc0) |
| 307 | + { |
| 308 | + if (size < 4) |
| 309 | + return -1; |
| 310 | + *sizep = size - 4; |
| 311 | + return (buf[3] & 0xc0) >> 6; |
| 312 | + } |
| 313 | + if (fread(buf, 12, 1, fp) != 1) |
| 314 | + return -1; |
| 315 | + lsize = adb_u32(buf + 4); |
| 316 | + lsize |= (unsigned long long)adb_u32(buf + 8) << 32; |
| 317 | + if (lsize < 16) |
| 318 | + return -1; |
| 319 | + *sizep = lsize - 16; |
| 320 | + return size; |
| 321 | +} |
| 322 | + |
320 | 323 | static const unsigned char * |
321 | 324 | adb_read_adb_blk(Pool *pool, FILE *fp, const char *fn, size_t *adblenp) |
322 | 325 | { |
@@ -391,7 +394,7 @@ apkv3_add_idx(Repo *repo, Repodata *data, FILE *fp, int flags) |
391 | 394 | unsigned int v, cnt, idx; |
392 | 395 | int idb = flags & APK_ADD_INSTALLED_DB ? 1 : 0; |
393 | 396 |
|
394 | | - if (fread(buf, 4, 1, fp) != 1 || memcmp(buf, (idb ? "idb" : "indx") , 4)) |
| 397 | + if (fread(buf, 4, 1, fp) != 1 || memcmp(buf, (idb ? "idb" : "indx") , 4) != 0) |
395 | 398 | { |
396 | 399 | pool_error(pool, -1, (idb ? "not an apkv3 installed database" : "not an apkv3 package index")); |
397 | 400 | return -1; |
|
0 commit comments