Skip to content

Commit 2006ef5

Browse files
author
Frank Chen
committed
Check that n + kBlockTrailerSize does not overflow before reading a block
PiperOrigin-RevId: 191666300
1 parent b9c191a commit 2006ef5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tensorflow/core/lib/io/format.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16+
#include <limits>
17+
1618
#include "tensorflow/core/lib/io/format.h"
1719

1820
#include "tensorflow/core/lib/core/coding.h"
@@ -84,6 +86,11 @@ Status ReadBlock(RandomAccessFile* file, const BlockHandle& handle,
8486
// Read the block contents as well as the type/crc footer.
8587
// See table_builder.cc for the code that built this structure.
8688
size_t n = static_cast<size_t>(handle.size());
89+
90+
if (kBlockTrailerSize > std::numeric_limits<size_t>::max() - n) {
91+
return errors::DataLoss("handle.size() too big");
92+
}
93+
8794
char* buf = new char[n + kBlockTrailerSize];
8895
StringPiece contents;
8996
Status s = file->Read(handle.offset(), n + kBlockTrailerSize, &contents, buf);

0 commit comments

Comments
 (0)