Bam reader robustness; allow threaded bam reading from Python

This commit is contained in:
rdb 2016-01-26 11:32:51 +01:00
parent a55d915aea
commit ea368dd559
3 changed files with 31 additions and 3 deletions

View File

@ -4465,6 +4465,9 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) {
set_fancy_bit(FB_effects, !_effects->is_empty()); set_fancy_bit(FB_effects, !_effects->is_empty());
set_fancy_bit(FB_tag, !_tag_data.empty()); set_fancy_bit(FB_tag, !_tag_data.empty());
// Mark the bounds stale.
++_next_update;
return pi; return pi;
} }

View File

@ -142,6 +142,12 @@ init() {
_file_stdfloat_double = scan.get_bool(); _file_stdfloat_double = scan.get_bool();
} }
if (scan.get_current_index() > header.get_length()) {
bam_cat.error()
<< "Bam header is too short.\n";
return false;
}
return true; return true;
} }
@ -1230,6 +1236,12 @@ p_read_object() {
int object_id = read_object_id(scan); int object_id = read_object_id(scan);
if (scan.get_current_index() > dg.get_length()) {
bam_cat.error()
<< "Found truncated datagram in bam stream\n";
return 0;
}
// There are two cases (not counting the special _remove_flag case, // There are two cases (not counting the special _remove_flag case,
// above). Either this is a new object definition, or this is a // above). Either this is a new object definition, or this is a
// reference to an object that was previously defined. // reference to an object that was previously defined.
@ -1271,6 +1283,12 @@ p_read_object() {
created_obj._ptr->fillin(scan, this); created_obj._ptr->fillin(scan, this);
_now_creating = was_creating; _now_creating = was_creating;
if (scan.get_remaining_size() > 0) {
bam_cat.warning()
<< "Skipping " << scan.get_remaining_size() << " remaining bytes "
<< "in datagram containing type " << type << "\n";
}
} else { } else {
// We are receiving a new object. Now we can call the factory // We are receiving a new object. Now we can call the factory
// to create the object. // to create the object.
@ -1371,6 +1389,13 @@ p_read_object() {
} }
} }
} }
// Sanity check that we read the expected number of bytes.
if (scan.get_current_index() > dg.get_length()) {
bam_cat.error()
<< "End of datagram reached while reading bam object "
<< type << ": " << (void *)created_obj._ptr << "\n";
}
} }
return object_id; return object_id;

View File

@ -144,8 +144,8 @@ PUBLISHED:
INLINE const LoaderOptions &get_loader_options() const; INLINE const LoaderOptions &get_loader_options() const;
INLINE void set_loader_options(const LoaderOptions &options); INLINE void set_loader_options(const LoaderOptions &options);
TypedWritable *read_object(); BLOCKING TypedWritable *read_object();
bool read_object(TypedWritable *&ptr, ReferenceCount *&ref_ptr); BLOCKING bool read_object(TypedWritable *&ptr, ReferenceCount *&ref_ptr);
INLINE bool is_eof() const; INLINE bool is_eof() const;
bool resolve(); bool resolve();