Skip to content

Commit

Permalink
Check that n + kBlockTrailerSize does not overflow before reading a b…
Browse files Browse the repository at this point in the history
…lock

PiperOrigin-RevId: 191666300
  • Loading branch information
Frank Chen committed Apr 17, 2018
1 parent b9c191a commit 2006ef5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tensorflow/core/lib/io/format.cc
Expand Up @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include <limits>

#include "tensorflow/core/lib/io/format.h"

#include "tensorflow/core/lib/core/coding.h"
Expand Down Expand Up @@ -84,6 +86,11 @@ Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle,
// Read the block contents as well as the type/crc footer.
// See table_builder.cc for the code that built this structure.
size_t n = static_cast<size_t>(handle.size());

if (kBlockTrailerSize > std::numeric_limits<size_t>::max() - n) {
return errors::DataLoss("handle.size() too big");
}

char* buf = new char[n + kBlockTrailerSize];
StringPiece contents;
Status s = file->Read(handle.offset(), n + kBlockTrailerSize, &contents, buf);
Expand Down

0 comments on commit 2006ef5

Please sign in to comment.