@@ -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}
285290static 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+
21012199int
21022200main (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}
0 commit comments