Skip to content

Commit ed2cc1f

Browse files
Merge pull request #158 from jeromekelleher/c_0.99.2_fixes
C 0.99.2 fixes
2 parents 02e2421 + 5d68315 commit ed2cc1f

File tree

6 files changed

+209
-4
lines changed

6 files changed

+209
-4
lines changed

c/CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
---------------------
2+
[0.99.2] - 2019-03-27
3+
---------------------
4+
5+
Bugfix release. Changes:
6+
7+
- Fix incorrect errors on tbl_collection_dump (#132)
8+
- Catch table overflows (#157)
9+
110
---------------------
211
[0.99.1] - 2019-01-24
312
---------------------

c/tests/test_tables.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,17 @@ test_table_collection_dump_errors(void)
274274

275275
ret = tsk_table_collection_init(&tables, 0);
276276
CU_ASSERT_EQUAL_FATAL(ret, 0);
277+
tables.sequence_length = 1.0;
278+
277279
ret = tsk_table_collection_dump(&tables, "/", 0);
278280
CU_ASSERT_TRUE(tsk_is_kas_error(ret));
279281
CU_ASSERT_EQUAL_FATAL(ret ^ (1 << TSK_KAS_ERR_BIT), KAS_ERR_IO);
280282
str = tsk_strerror(ret);
281283
CU_ASSERT_TRUE(strlen(str) > 0);
282284

285+
/* We'd like to catch close errors also, but it's hard to provoke them
286+
* without intercepting calls to fclose() */
287+
283288
tsk_table_collection_free(&tables);
284289
}
285290
static void
@@ -2098,6 +2103,99 @@ test_load_reindex(void)
20982103
tsk_treeseq_free(&ts);
20992104
}
21002105

2106+
static void
2107+
test_table_overflow(void)
2108+
{
2109+
int ret;
2110+
tsk_table_collection_t tables;
2111+
tsk_size_t max_rows = ((tsk_size_t) INT32_MAX) + 1;
2112+
2113+
ret = tsk_table_collection_init(&tables, 0);
2114+
CU_ASSERT_EQUAL_FATAL(ret, 0);
2115+
2116+
/* Simulate overflows */
2117+
tables.individuals.max_rows = max_rows;
2118+
tables.individuals.num_rows = max_rows;
2119+
ret = tsk_individual_table_add_row(&tables.individuals, 0, 0, 0, NULL, 0);
2120+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2121+
2122+
tables.nodes.max_rows = max_rows;
2123+
tables.nodes.num_rows = max_rows;
2124+
ret = tsk_node_table_add_row(&tables.nodes, 0, 0, 0, 0, NULL, 0);
2125+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2126+
2127+
tables.edges.max_rows = max_rows;
2128+
tables.edges.num_rows = max_rows;
2129+
ret = tsk_edge_table_add_row(&tables.edges, 0, 0, 0, 0);
2130+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2131+
2132+
tables.migrations.max_rows = max_rows;
2133+
tables.migrations.num_rows = max_rows;
2134+
ret = tsk_migration_table_add_row(&tables.migrations, 0, 0, 0, 0, 0, 0);
2135+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2136+
2137+
tables.sites.max_rows = max_rows;
2138+
tables.sites.num_rows = max_rows;
2139+
ret = tsk_site_table_add_row(&tables.sites, 0, 0, 0, 0, 0);
2140+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2141+
2142+
tables.mutations.max_rows = max_rows;
2143+
tables.mutations.num_rows = max_rows;
2144+
ret = tsk_mutation_table_add_row(&tables.mutations, 0, 0, 0, 0, 0, 0, 0);
2145+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2146+
2147+
tables.provenances.max_rows = max_rows;
2148+
tables.provenances.num_rows = max_rows;
2149+
ret = tsk_provenance_table_add_row(&tables.provenances, 0, 0, 0, 0);
2150+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2151+
2152+
tables.populations.max_rows = max_rows;
2153+
tables.populations.num_rows = max_rows;
2154+
ret = tsk_population_table_add_row(&tables.populations, 0, 0);
2155+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_TABLE_OVERFLOW);
2156+
2157+
tsk_table_collection_free(&tables);
2158+
}
2159+
2160+
static void
2161+
test_column_overflow(void)
2162+
{
2163+
int ret;
2164+
tsk_table_collection_t tables;
2165+
tsk_size_t too_big = ((tsk_size_t) INT32_MAX) + 2;
2166+
2167+
ret = tsk_table_collection_init(&tables, 0);
2168+
CU_ASSERT_EQUAL_FATAL(ret, 0);
2169+
2170+
ret = tsk_individual_table_add_row(&tables.individuals, 0, NULL, too_big, NULL, 0);
2171+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2172+
ret = tsk_individual_table_add_row(&tables.individuals, 0, NULL, 0, NULL, too_big);
2173+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2174+
2175+
ret = tsk_node_table_add_row(&tables.nodes, 0, 0, 0, 0, NULL, too_big);
2176+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2177+
2178+
ret = tsk_site_table_add_row(&tables.sites, 0, NULL, too_big, NULL, 0);
2179+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2180+
ret = tsk_site_table_add_row(&tables.sites, 0, NULL, 0, NULL, too_big);
2181+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2182+
2183+
ret = tsk_mutation_table_add_row(&tables.mutations, 0, 0, 0, NULL, 0, NULL, too_big);
2184+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2185+
ret = tsk_mutation_table_add_row(&tables.mutations, 0, 0, 0, NULL, too_big, NULL, 0);
2186+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2187+
2188+
ret = tsk_provenance_table_add_row(&tables.provenances, NULL, too_big, NULL, 0);
2189+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2190+
ret = tsk_provenance_table_add_row(&tables.provenances, NULL, 0, NULL, too_big);
2191+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2192+
2193+
ret = tsk_population_table_add_row(&tables.populations, NULL, too_big);
2194+
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_COLUMN_OVERFLOW);
2195+
2196+
tsk_table_collection_free(&tables);
2197+
}
2198+
21012199
int
21022200
main(int argc, char **argv)
21032201
{
@@ -2124,8 +2222,11 @@ main(int argc, char **argv)
21242222
{"test_dump_load_empty", test_dump_load_empty},
21252223
{"test_dump_load_unsorted", test_dump_load_unsorted},
21262224
{"test_load_reindex", test_load_reindex},
2225+
{"test_table_overflow", test_table_overflow},
2226+
{"test_column_overflow", test_column_overflow},
21272227
{NULL, NULL},
21282228
};
21292229

2230+
21302231
return test_main(tests, argc, argv);
21312232
}

c/tskit/core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ tsk_strerror_internal(int err)
293293
case TSK_ERR_TABLES_NOT_INDEXED:
294294
ret = "Table collection must be indexed";
295295
break;
296+
case TSK_ERR_TABLE_OVERFLOW:
297+
ret = "Table too large; cannot allocate more than 2**31 rows.";
298+
break;
299+
case TSK_ERR_COLUMN_OVERFLOW:
300+
ret = "Table column too large; cannot be more than 2**31 bytes.";
301+
break;
296302

297303
/* Limitations */
298304
case TSK_ERR_ONLY_INFINITE_SITES:

c/tskit/core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ to the API or ABI are introduced, i.e., the addition of a new function.
8080
The library patch version. Incremented when any changes not relevant to the
8181
to the API or ABI are introduced, i.e., internal refactors of bugfixes.
8282
*/
83-
#define TSK_VERSION_PATCH 1
83+
#define TSK_VERSION_PATCH 2
8484
/** @} */
8585

8686
/* Node flags */
@@ -189,6 +189,8 @@ of tskit.
189189
#define TSK_ERR_BAD_TABLE_POSITION -700
190190
#define TSK_ERR_BAD_SEQUENCE_LENGTH -701
191191
#define TSK_ERR_TABLES_NOT_INDEXED -702
192+
#define TSK_ERR_TABLE_OVERFLOW -703
193+
#define TSK_ERR_COLUMN_OVERFLOW -704
192194

193195
/* Limitations */
194196
#define TSK_ERR_ONLY_INFINITE_SITES -800

0 commit comments

Comments
 (0)