bits8 mask;
bitlen = pq_getmsgint(buf, sizeof(int32));
- if (bitlen < 0)
+ if (bitlen < 0 || bitlen > VARBITMAXLEN)
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid length in external bit string")));
bits8 mask;
/* No work if typmod is invalid or supplied data matches it already */
- if (len <= 0 || len == VARBITLEN(arg))
+ if (len <= 0 || len > VARBITMAXLEN || len == VARBITLEN(arg))
PG_RETURN_VARBIT_P(arg);
if (!isExplicit)
bits8 mask;
bitlen = pq_getmsgint(buf, sizeof(int32));
- if (bitlen < 0)
+ if (bitlen < 0 || bitlen > VARBITMAXLEN)
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid length in external bit string")));
/* Negative shift is a shift to the right */
if (shft < 0)
+ {
+ /* Prevent integer overflow in negation */
+ if (shft < -VARBITMAXLEN)
+ shft = -VARBITMAXLEN;
PG_RETURN_DATUM(DirectFunctionCall2(bitshiftright,
VarBitPGetDatum(arg),
Int32GetDatum(-shft)));
+ }
result = (VarBit *) palloc(VARSIZE(arg));
SET_VARSIZE(result, VARSIZE(arg));
/* Negative shift is a shift to the left */
if (shft < 0)
+ {
+ /* Prevent integer overflow in negation */
+ if (shft < -VARBITMAXLEN)
+ shft = -VARBITMAXLEN;
PG_RETURN_DATUM(DirectFunctionCall2(bitshiftleft,
VarBitPGetDatum(arg),
Int32GetDatum(-shft)));
+ }
result = (VarBit *) palloc(VARSIZE(arg));
SET_VARSIZE(result, VARSIZE(arg));
int destbitsleft,
srcbitsleft;
- if (typmod <= 0)
+ if (typmod <= 0 || typmod > VARBITMAXLEN)
typmod = 1; /* default bit length */
rlen = VARBITTOTALLEN(typmod);
int destbitsleft,
srcbitsleft;
- if (typmod <= 0)
+ if (typmod <= 0 || typmod > VARBITMAXLEN)
typmod = 1; /* default bit length */
rlen = VARBITTOTALLEN(typmod);