[MOAB-dev] r1275 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Fri Sep 14 11:05:59 CDT 2007
Author: kraftche
Date: 2007-09-14 11:05:59 -0500 (Fri, 14 Sep 2007)
New Revision: 1275
Modified:
MOAB/trunk/ReadHDF5.cpp
Log:
- report error when invalid set contents are encountered during read
- check for invalid set parent/child handles and report error
- replace asserts for invalid set content length with proper error checks
- simplify id->handle converstion for set parents/children
Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp 2007-09-14 16:03:31 UTC (rev 1274)
+++ MOAB/trunk/ReadHDF5.cpp 2007-09-14 16:05:59 UTC (rev 1275)
@@ -618,11 +618,16 @@
// convert data from file ids to MBEntityHandles and add to set
if (ranged)
{
- assert(count % 2 == 0);
+ if (count % 2 != 0) {
+ readUtil->report_error( "Invalid ranged set contents spec." );
+ return MB_FAILURE;
+ }
MBRange range;
rval = convert_range_to_handle( buffer, count / 2, range );
- if (MB_SUCCESS != rval)
+ if (MB_SUCCESS != rval) {
+ readUtil->report_error( "Invalid entities in set contents" );
return rval;
+ }
rval = iFace->add_entities( h, range );
if (MB_SUCCESS != rval)
return rval;
@@ -630,8 +635,10 @@
else
{
rval = convert_id_to_handle( buffer, count );
- if (MB_SUCCESS != rval)
+ if (MB_SUCCESS != rval) {
+ readUtil->report_error( "Invalid entities in set contents" );
return rval;
+ }
rval = iFace->add_entities( h, buffer, count );
if (MB_SUCCESS != rval)
return rval;
@@ -645,7 +652,7 @@
// read data for sets in [r,i)
size_t count = offsets[i-1] + 1 - file_offset;
- mhdf_readSetParentsChildren( data_id, file_offset, count, handleType, buffer, &status );
+ mhdf_readSetData( data_id, file_offset, count, handleType, buffer, &status );
if (mhdf_isError( &status )) {
readUtil->report_error( mhdf_message( &status ) );
return MB_FAILURE;
@@ -661,11 +668,16 @@
if (ranged)
{
- assert(count % 2 == 0);
+ if (count % 2 != 0) {
+ readUtil->report_error( "Invalid ranged set contenst spec." );
+ return MB_FAILURE;
+ }
MBRange range;
rval = convert_range_to_handle( buffer+mem_offset, count / 2, range );
- if (MB_SUCCESS != rval)
+ if (MB_SUCCESS != rval) {
+ readUtil->report_error( "Invalid entities in set contents" );
return rval;
+ }
rval = iFace->add_entities( h, range );
if (MB_SUCCESS != rval)
return rval;
@@ -673,8 +685,10 @@
else
{
rval = convert_id_to_handle( buffer+mem_offset, count );
- if (MB_SUCCESS != rval)
+ if (MB_SUCCESS != rval) {
+ readUtil->report_error( "Invalid entities in set contents" );
return rval;
+ }
rval = iFace->add_entities( h, buffer+mem_offset, count );
if (MB_SUCCESS != rval)
return rval;
@@ -707,6 +721,7 @@
// use the existing buffer for storing set child lists
MBEntityHandle* buffer = (MBEntityHandle*)dataBuffer;
size_t chunk_size = bufferSize / sizeof(MBEntityHandle);
+ const size_t total_sets = setSet.range.size();
unsigned long set_offset = 0; /* running offset into description table */
unsigned long sets_remaining = setSet.range.size();
@@ -751,8 +766,14 @@
file_offset += count;
// convert from file_ids to set handles
- for (size_t j = 0; j < count; ++j)
- buffer[j] = *(setSet.range.begin() += (buffer[j] - setSet.first_id));
+ for (size_t j = 0; j < count; ++j) {
+ buffer[j] -= setSet.first_id;
+ if (buffer[j] >= total_sets) {
+ readUtil->report_error("Invalid set %s ID", parents ? "parent" : "child" );
+ return MB_FAILURE;
+ }
+ buffer[j] += setSet.range.front();
+ }
if (parents)
rval = iFace->add_parent_meshsets( h, buffer, count );
@@ -776,8 +797,14 @@
}
// convert from file_ids to set handles
- for (size_t j = 0; j < count; ++j)
- buffer[j] = *(setSet.range.begin() += (buffer[j] - setSet.first_id));
+ for (size_t j = 0; j < count; ++j) {
+ buffer[j] -= setSet.first_id;
+ if (buffer[j] >= total_sets) {
+ readUtil->report_error("Invalid set %s ID", parents ? "parent" : "child" );
+ return MB_FAILURE;
+ }
+ buffer[j] += setSet.range.front();
+ }
// add children to each set
size_t mem_offset = 0;
More information about the moab-dev
mailing list