Skip to content

Commit

Permalink
Fix Coverity warning in detoaster
Browse files Browse the repository at this point in the history
Coverity doesn't understand that the relevant check is performed inside
palloc().
  • Loading branch information
akuzm committed Dec 22, 2023
1 parent 781cbe3 commit 467e837
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tsl/src/nodes/decompress_chunk/detoaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <utils/relcache.h>

#include <compat/compat.h>
#include <compression/compression.h>
#include "debug_assert.h"

#if PG14_LT
Expand Down Expand Up @@ -393,6 +394,14 @@ detoaster_detoast_attr(struct varlena *attr, Detoaster *detoaster)
*/
Ensure(VARATT_IS_SHORT(attr), "got unexpected TOAST type for compressed data");

/*
* Check that the size of datum is not less than the size of header, which
* could lead to data_size of UINT64_MAX. This is possible in case of
* TOAST data corruption. Postgres doesn't specifically check for this,
* because in any case it will be detected by the subsequent palloc call,
* but we do it to silence the Coverity warning.
*/
CheckCompressedData(VARSIZE_SHORT(attr) >= VARHDRSZ_SHORT);
Size data_size = VARSIZE_SHORT(attr) - VARHDRSZ_SHORT;
Size new_size = data_size + VARHDRSZ;
struct varlena *new_attr;
Expand Down

0 comments on commit 467e837

Please sign in to comment.