From db7ae0a485de0bbb4acd2ec2391d634b2ce9c854 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Fri, 6 Jul 2018 16:07:29 -0700 Subject: [PATCH] Fix a map lookup that may throw exception. (#4098) Summary: `std::map::at(key)` throws std::out_of_range if key does not exist. Current code does not handle this. Although this case is unlikely, I feel it's safe to use `std::map::find`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4098 Differential Revision: D8753865 Pulled By: riversand963 fbshipit-source-id: 9a9ba43badb0fb5e0d24cd87903931fd12f3f8ec --- db/external_sst_file_ingestion_job.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/external_sst_file_ingestion_job.cc b/db/external_sst_file_ingestion_job.cc index 4042961c9..c4ec343c8 100644 --- a/db/external_sst_file_ingestion_job.cc +++ b/db/external_sst_file_ingestion_job.cc @@ -336,12 +336,14 @@ Status ExternalSstFileIngestionJob::GetIngestedFileInfo( // Set the global sequence number file_to_ingest->original_seqno = DecodeFixed64(seqno_iter->second.c_str()); - file_to_ingest->global_seqno_offset = props->properties_offsets.at( + auto offsets_iter = props->properties_offsets.find( ExternalSstFilePropertyNames::kGlobalSeqno); - - if (file_to_ingest->global_seqno_offset == 0) { + if (offsets_iter == props->properties_offsets.end() || + offsets_iter->second == 0) { + file_to_ingest->global_seqno_offset = 0; return Status::Corruption("Was not able to find file global seqno field"); } + file_to_ingest->global_seqno_offset = offsets_iter->second; } else if (file_to_ingest->version == 1) { // SST file V1 should not have global seqno field assert(seqno_iter == uprops.end());