if (!(c & 128))
{
x = (x << 7) | c;
- if (max && x >= max)
+ if (max && x >= (unsigned int)max)
{
data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "read_id: id too large (%u/%u)", x, max);
return 0;
continue;
}
x = (x << 6) | (c & 63);
- if (max && x >= max)
+ if (max && x >= (unsigned int)max)
{
data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "read_idarray: id too large (%u/%u)", x, max);
return 0;
continue;
}
x = (x << 6) | (c & 63);
- if (max && x >= max)
+ if (max && x >= (unsigned int)max)
{
data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "data_read_idarray: id too large (%u/%u)", x, max);
data->error = SOLV_ERROR_ID_RANGE;
break;
}
- *store++ = x;
+ *store++ = map ? map[x] : x;
if ((c & 64) == 0)
break;
x = 0;
}
x = old + (x - 1);
old = x;
- if (max && x >= max)
+ if (max && x >= (unsigned int)max)
{
data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "data_read_rel_idarray: id too large (%u/%u)", x, max);
break;
static void
incore_add_blob(Repodata *data, unsigned char *buf, int len)
{
- if (data->incoredatafree < len)
+ if (data->incoredatafree < (unsigned int)len)
{
data->incoredata = solv_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK + len);
data->incoredatafree = INCORE_ADD_CHUNK + len;
{
Pool *pool = repo->pool;
int i, l;
- unsigned int numid, numrel, numdir, numsolv;
- unsigned int numkeys, numschemata;
+ int numid, numrel, numdir, numsolv;
+ int numkeys, numschemata;
Offset sizeid;
Offset *str; /* map Id -> Offset into string space */
return pool_error(pool, SOLV_ERROR_UNSUPPORTED, "unsupported SOLV version");
}
- numid = read_u32(&data);
- numrel = read_u32(&data);
- numdir = read_u32(&data);
- numsolv = read_u32(&data);
- numkeys = read_u32(&data);
- numschemata = read_u32(&data);
+ numid = (int)read_u32(&data);
+ numrel = (int)read_u32(&data);
+ numdir = (int)read_u32(&data);
+ numsolv = (int)read_u32(&data);
+ numkeys = (int)read_u32(&data);
+ numschemata = (int)read_u32(&data);
solvflags = read_u32(&data);
- if (numdir && numdir < 2)
+ if (numid < 0 || numid >= 0x20000000)
+ return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of ids");
+ if (numrel < 0 || numrel >= 0x20000000)
+ return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of rels");
+ if (numdir && (numdir < 2 || numdir >= 0x20000000))
return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of dirs");
+ if (numsolv < 0 || numsolv >= 0x20000000)
+ return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of solvables");
+ if (numkeys < 0 || numkeys >= 0x20000000)
+ return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of keys");
+ if (numschemata < 0 || numschemata >= 0x20000000)
+ return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of schematas");
if (numrel && (flags & REPO_LOCALPOOL) != 0)
return pool_error(pool, SOLV_ERROR_CORRUPT, "relations are forbidden in a local pool");
unsigned int pfsize = read_u32(&data);
char *prefix = solv_malloc(pfsize);
char *pp = prefix;
- char *old_str = 0;
+ char *old_str = strsp;
char *dest = strsp;
int freesp = sizeid;
/* alloc id map for name and rel Ids. this maps ids in the solv files
* to the ids in our pool */
idmap = solv_calloc(numid + numrel, sizeof(Id));
-
- /* grow hash if needed, otherwise reuse */
- hashmask = mkmask(spool->nstrings + numid);
+ stringpool_resize_hash(spool, numid);
+ hashtbl = spool->stringhashtbl;
+ hashmask = spool->stringhashmask;
#if 0
POOL_DEBUG(SOLV_DEBUG_STATS, "read %d strings\n", numid);
- POOL_DEBUG(SOLV_DEBUG_STATS, "string hash buckets: %d, old %d\n", hashmask + 1, spool->stringhashmask + 1);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
#endif
- if (hashmask > spool->stringhashmask)
- {
- spool->stringhashtbl = solv_free(spool->stringhashtbl);
- spool->stringhashmask = hashmask;
- spool->stringhashtbl = hashtbl = solv_calloc(hashmask + 1, sizeof(Id));
- for (i = 1; i < spool->nstrings; i++)
- {
- h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
- hh = HASHCHAIN_START;
- while (hashtbl[h])
- h = HASHCHAIN_NEXT(h, hh, hashmask);
- hashtbl[h] = i;
- }
- }
- else
- {
- hashtbl = spool->stringhashtbl;
- hashmask = spool->stringhashmask;
- }
-
/*
* run over strings and merge with pool.
+ * we could use stringpool_str2id, but this is faster.
* also populate id map (maps solv Id -> pool Id)
*/
for (i = 1; i < numid; i++)
idmap[i] = id; /* repo relative -> pool relative */
sp += l; /* next string */
}
- if (hashmask > mkmask(spool->nstrings + 8192))
- {
- spool->stringhashtbl = solv_free(spool->stringhashtbl);
- spool->stringhashmask = 0;
- }
stringpool_shrink(spool); /* vacuum */
}
pool->rels = solv_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
ran = pool->rels;
- /* grow hash if needed, otherwise reuse */
- hashmask = mkmask(pool->nrels + numrel);
+ pool_resize_rels_hash(pool, numrel);
+ hashtbl = pool->relhashtbl;
+ hashmask = pool->relhashmask;
#if 0
POOL_DEBUG(SOLV_DEBUG_STATS, "read %d rels\n", numrel);
- POOL_DEBUG(SOLV_DEBUG_STATS, "rel hash buckets: %d, old %d\n", hashmask + 1, pool->relhashmask + 1);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
#endif
- if (hashmask > pool->relhashmask)
- {
- pool->relhashtbl = solv_free(pool->relhashtbl);
- pool->relhashmask = hashmask;
- pool->relhashtbl = hashtbl = solv_calloc(hashmask + 1, sizeof(Id));
- for (i = 1; i < pool->nrels; i++)
- {
- h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
- hh = HASHCHAIN_START;
- while (hashtbl[h])
- h = HASHCHAIN_NEXT(h, hh, hashmask);
- hashtbl[h] = i;
- }
- }
- else
- {
- hashtbl = pool->relhashtbl;
- hashmask = pool->relhashmask;
- }
/*
* read RelDeps from repo
}
idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
}
- if (hashmask > mkmask(pool->nrels + 4096))
- {
- pool->relhashtbl = solv_free(pool->relhashtbl);
- pool->relhashmask = 0;
- }
pool_shrink_rels(pool); /* vacuum */
}
{
id = read_id(&data, i + numid);
if (id >= numid)
- data.dirpool.dirs[i] = -(id - numid);
- else if (idmap)
- data.dirpool.dirs[i] = idmap[id];
- else
- data.dirpool.dirs[i] = id;
+ {
+ data.dirpool.dirs[i++] = -(id - numid);
+ if (i >= numdir)
+ {
+ data.error = pool_error(pool, SOLV_ERROR_CORRUPT, "last dir entry is not a component");
+ break;
+ }
+ id = read_id(&data, numid);
+ }
+ if (idmap)
+ id = idmap[id];
+ data.dirpool.dirs[i] = id;
+ if (id <= 0)
+ data.error = pool_error(pool, SOLV_ERROR_CORRUPT, "bad dir component");
}
}