mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
Basic checks on file to ensure it's an mdb database. bug # 587739
This commit is contained in:
parent
dd534f39dc
commit
8c68edba1f
@ -58,8 +58,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
fseek(in,(pg*pg_size),SEEK_SET);
|
||||
i = 0;
|
||||
while (length = fread(data,1,16,in)) {
|
||||
sprintf(addr, "%06x", i);
|
||||
while ((length = fread(data,1,16,in))) {
|
||||
sprintf(addr, "%06lx", i);
|
||||
//if (!strcmp(&addr[3],"000") || (!jet4 && !strcmp(&addr[3],"800")) &&
|
||||
//pg) break;
|
||||
if (!strcmp(&addr[3],"000") || (!jet4 && !strcmp(&addr[3],"800"))) {
|
||||
|
@ -71,6 +71,8 @@ int type;
|
||||
/* mdb_table_dump(&msysobj); */
|
||||
|
||||
table = mdb_read_table(&msysobj);
|
||||
if (!table) return NULL;
|
||||
|
||||
mdb_read_columns(table);
|
||||
|
||||
mdb_bind_column(table, 1, parentid);
|
||||
|
@ -106,18 +106,25 @@ MdbFile *f;
|
||||
fprintf(stderr,"Couldn't open file %s\n",f->filename);
|
||||
return NULL;
|
||||
}
|
||||
f->refs++;
|
||||
if (!mdb_read_pg(mdb, 0)) {
|
||||
fprintf(stderr,"Couldn't read first page.\n");
|
||||
return NULL;
|
||||
}
|
||||
if (mdb->pg_buf[0] != 0) {
|
||||
close(f->fd);
|
||||
return NULL;
|
||||
}
|
||||
f->jet_version = mdb_pg_get_int32(mdb, 0x14);
|
||||
if (IS_JET4(mdb)) {
|
||||
mdb->fmt = &MdbJet4Constants;
|
||||
} else {
|
||||
} else if (IS_JET3(mdb)) {
|
||||
mdb->fmt = &MdbJet3Constants;
|
||||
} else {
|
||||
fprintf(stderr,"Unknown Jet version.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f->refs++;
|
||||
return mdb;
|
||||
}
|
||||
MdbHandle *mdb_open(char *filename)
|
||||
|
@ -55,6 +55,8 @@ int rownum, row_start, row_end;
|
||||
table = mdb_alloc_tabledef(entry);
|
||||
|
||||
mdb_read_pg(mdb, entry->table_pg);
|
||||
if (mdb->pg_buf[0] != 0x02) return NULL; /* not a valid table def page */
|
||||
|
||||
len = mdb_pg_get_int16(mdb,8);
|
||||
|
||||
table->num_rows = mdb_pg_get_int32(mdb, fmt->tab_num_rows_offset);
|
||||
|
@ -97,7 +97,10 @@ main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mdb_read_catalog(mdb, MDB_TABLE);
|
||||
if (!mdb_read_catalog (mdb, MDB_TABLE)) {
|
||||
fprintf(stderr,"File does not appear to be an Access database\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (i=0;i<mdb->num_catalog;i++) {
|
||||
entry = g_ptr_array_index(mdb->catalog,i);
|
||||
|
@ -74,9 +74,11 @@ main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* read the catalog */
|
||||
|
||||
mdb_read_catalog (mdb, MDB_TABLE);
|
||||
/* read the catalog */
|
||||
if (!mdb_read_catalog (mdb, MDB_TABLE)) {
|
||||
fprintf(stderr,"File does not appear to be an Access database\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* loop over each entry in the catalog */
|
||||
|
||||
|
@ -65,7 +65,10 @@ int opt;
|
||||
|
||||
|
||||
/* read the catalog */
|
||||
mdb_read_catalog (mdb, MDB_TABLE);
|
||||
if (!mdb_read_catalog (mdb, MDB_TABLE)) {
|
||||
fprintf(stderr,"File does not appear to be an Access database\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* loop over each entry in the catalog */
|
||||
for (i=0; i < mdb->num_catalog; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user