}
// navigate to the requested part in the manifest
RGWObjManifest::obj_iterator end = manifest->obj_end(dpp);
- if (end.get_cur_part_id() == 0) { // not multipart
+ const int last_part_id = end.get_cur_part_id();
+ if (last_part_id == 0) { // not multipart
ldpp_dout(dpp, 20) << "object does not have a multipart manifest" << dendl;
return -ERR_INVALID_PART;
}
if (parts_count) {
- *parts_count = end.get_cur_part_id() - 1;
+ // when a multipart upload only contains a single part, the last part id
+ // is off by one. don't let parts_count go to 0
+ *parts_count = std::max(1, last_part_id - 1);
}
ldpp_dout(dpp, 20) << "seeking to part #" << part_num
<< " in the object manifest" << dendl;
do {
++iter;
gen.create_next(iter.get_ofs() - part_offset);
- } while (iter.get_cur_part_id() == part_num);
+ } while (iter != end && iter.get_cur_part_id() == part_num);
// update the object size
sm->state.size = part_manifest.get_obj_size();