/*
* repo_solv.c
- *
+ *
* Add a repo in solv format
- *
+ *
*/
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;
}
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 */
char *sp; /* pointer into string space */
Id *idmap; /* map of repo Ids to pool Ids */
Id id, type;
- unsigned int hashmask, h;
- int hh;
- Id *hashtbl;
+ Hashval hashmask, h, hh;
+ Hashtable hashtbl;
Id name, evr, did;
int relflags;
Reldep *ran;
extendstart = repo->start;
extendend = repo->end;
}
-
+
memset(&data, 0, sizeof(data));
data.repo = repo;
data.fp = fp;
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");
/*
* read strings and Ids
- *
+ *
*/
-
+
/*
* alloc buffers
*/
spool = &pool->ss;
/* alloc max needed string buffer and string pointers, will shrink again later */
#if 0
- spool->stringspace = solv_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
+ spool->stringspace = solv_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
spool->strings = solv_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
#else
spool->sstrings += sizeid + 1;
{
data.localpool = 1;
spool = &data.spool;
- spool->stringspace = solv_malloc(7 + sizeid + 1);
+ spool->stringspace = solv_malloc(7 + sizeid + 1);
spool->strings = solv_malloc2(numid < 2 ? 2 : numid, sizeof(Offset));
strcpy(spool->stringspace, "<NULL>");
spool->sstrings = 7;
/*
* read string data and append to old string space
*/
-
+
strsp = spool->stringspace + spool->sstrings; /* append new entries */
if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
{
if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
- return pool_error(pool, SOLV_ERROR_EOF, "read error while reading strings");
+ {
+ repodata_freedata(&data);
+ return pool_error(pool, SOLV_ERROR_EOF, "read error while reading strings");
+ }
}
else
{
int freesp = sizeid;
if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
- {
+ {
solv_free(prefix);
- return pool_error(pool, SOLV_ERROR_EOF, "read error while reading strings");
+ repodata_freedata(&data);
+ return pool_error(pool, SOLV_ERROR_EOF, "read error while reading strings");
}
for (i = 1; i < numid; i++)
{
if (freesp < 0)
{
solv_free(prefix);
+ repodata_freedata(&data);
return pool_error(pool, SOLV_ERROR_OVERFLOW, "overflow while expanding strings");
}
if (same)
}
solv_free(prefix);
if (freesp != 0)
- return pool_error(pool, SOLV_ERROR_CORRUPT, "expanding strings size mismatch");
+ {
+ repodata_freedata(&data);
+ return pool_error(pool, SOLV_ERROR_CORRUPT, "expanding strings size mismatch");
+ }
}
strsp[sizeid] = 0; /* make string space \0 terminated */
sp = strsp;
if (*sp)
{
/* we need id 1 to be '' for directories */
+ repodata_freedata(&data);
return pool_error(pool, SOLV_ERROR_CORRUPT, "store strings don't start with an empty string");
}
for (i = 1; i < spool->nstrings; i++)
{
if (sp >= strsp + sizeid && numid >= 2)
- return pool_error(pool, SOLV_ERROR_OVERFLOW, "not enough strings");
+ {
+ repodata_freedata(&data);
+ return pool_error(pool, SOLV_ERROR_OVERFLOW, "not enough strings");
+ }
str[i] = sp - spool->stringspace;
sp += strlen(sp) + 1;
}
spool->nstrings = oldnstrings;
spool->sstrings = oldsstrings;
stringpool_freehash(spool);
+ repodata_freedata(&data);
return pool_error(pool, SOLV_ERROR_OVERFLOW, "not enough strings %d %d", i, numid);
}
if (!*sp) /* empty string */
stringpool_shrink(spool); /* vacuum */
}
-
+
/******* Part 2: Relation IDs ***************************************/
/*
* read RelDeps
- *
+ *
*/
-
+
if (numrel)
{
/* extend rels */
/* cannot handle mapped ids in vertical */
if (!(flags & REPO_LOCALPOOL) && keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET && (type == REPOKEY_TYPE_ID || type == REPOKEY_TYPE_IDARRAY))
data.error = pool_error(pool, SOLV_ERROR_UNSUPPORTED, "mapped ids are not supported for STORAGE_VERTICAL_OFFSET");
-
+
if (keys[i].type == REPOKEY_TYPE_CONSTANTID && idmap)
keys[i].size = idmap[keys[i].size];
#if 0
}
/******* Part 5: Schemata ********************************************/
-
+
id = read_id(&data, 0);
schemadata = solv_calloc(id + 1, sizeof(Id));
schemadatap = schemadata + 1;
case REPOKEY_TYPE_ID:
dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data);
if (s && id == SOLVABLE_NAME)
- s->name = did;
+ s->name = did;
else if (s && id == SOLVABLE_ARCH)
- s->arch = did;
+ s->arch = did;
else if (s && id == SOLVABLE_EVR)
- s->evr = did;
+ s->evr = did;
else if (s && id == SOLVABLE_VENDOR)
- s->vendor = did;
+ s->vendor = did;
else if (keys[key].storage == KEY_STORAGE_INCORE)
incore_add_id(&data, did);
#if 0
data.incoredata = solv_realloc(data.incoredata, data.incoredatalen);
data.incoredatafree = 0;
}
+ solv_free(idmap);
+
+ /* fixup the special idarray type */
+ for (i = 1; i < numkeys; i++)
+ if (keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
+ keys[i].type = REPOKEY_TYPE_IDARRAY;
for (i = 1; i < numkeys; i++)
if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
{
Id fileoffset = 0;
unsigned int pagesize;
-
+
/* we have vertical data, make it available */
data.verticaloffset = solv_calloc(numkeys, sizeof(Id));
for (i = 1; i < numkeys; i++)
}
data.lastverticaloffset = fileoffset;
pagesize = read_u32(&data);
- data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
- if (data.error == SOLV_ERROR_EOF)
- pool_error(pool, data.error, "repopagestore setup: unexpected EOF");
- else if (data.error)
- pool_error(pool, data.error, "repopagestore setup failed");
- }
- else
- {
- /* no longer needed */
- data.fp = 0;
+ if (!data.error)
+ {
+ data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
+ if (data.error == SOLV_ERROR_EOF)
+ pool_error(pool, data.error, "repopagestore setup: unexpected EOF");
+ else if (data.error)
+ pool_error(pool, data.error, "repopagestore setup failed");
+ }
}
- solv_free(idmap);
+ data.fp = 0; /* no longer needed */
if (data.error)
{
- /* XXX: free repodata? */
- return data.error;
+ i = data.error;
+ repodata_freedata(&data);
+ return i;
}
if (parent)