1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-10-23 21:28:56 +03:00

Error on zero-size pack fields.

A pack written by pckWrite always ends with an end tag, so a nested pack is at least one byte. A zero-size pack field from corrupt data was read into an empty buffer with no allocation, which failed the buffer != NULL assertion in pckReadNewC() in debug builds. Production builds failed with unexpected EOF on the first read from the empty pack.

Error with invalid pack size in pckReadPack() and pckReadPackReadConst() when the size of a pack field is zero.
This commit is contained in:
David Steele
2026-10-12 11:32:44 +02:00
parent 0966ebbb3e
commit 950c1e149f
2 changed files with 15 additions and 0 deletions

View File

@@ -1048,6 +1048,9 @@ pckReadPackReadConst(PackRead *const this, PckReadPackParam param)
// Read the tag
pckReadTag(this, &param.id, pckTypeMapPack, false);
// A pack has at least the end tag
CHECK(FormatError, this->tagNextSize > 0, "invalid pack size");
PackRead *const result = pckReadNewC(pckReadBufPtr(this), pckReadSize(this));
pckReadConsumeBuffer(this);
@@ -1071,6 +1074,9 @@ pckReadPack(PackRead *const this, PckReadPackParam param)
// Read the tag
pckReadTag(this, &param.id, pckTypeMapPack, false);
// A pack has at least the end tag
CHECK(FormatError, this->tagNextSize > 0, "invalid pack size");
// Get the pack size
Buffer *const result = OBJ_NAME(bufNew(this->tagNextSize), Pack::Buffer);

View File

@@ -360,6 +360,15 @@ testRun(void)
TEST_RESULT_BOOL(pckReadBoolP(packRead), false, "read bool");
TEST_ERROR(pckReadNext(packRead), FormatError, "invalid field id");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on zero-size pack");
TEST_ASSIGN(packRead, pckReadNew(pckFromBuf(BUFSTRDEF("\360\002\000"))), "new read");
TEST_ERROR(pckReadPackReadP(packRead), FormatError, "invalid pack size");
TEST_ASSIGN(packRead, pckReadNew(pckFromBuf(BUFSTRDEF("\360\002\000"))), "new read");
TEST_ERROR(pckReadPackReadConstP(packRead), FormatError, "invalid pack size");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("read const packs");