Skip to content
This repository was archived by the owner on Oct 25, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/rdb_transcoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ static int rdbTranscoderRun(rdbTranscoder *t, const uint8_t *data, size_t len) {
}
}
if (r == STREAM_PUSH_READER_NEED_OUTPUT) continue;
/* OK: input consumed. FRAME_DONE: the frame ended; the caller has already
* excluded any trailing bytes, so there is nothing more to feed. */
/* The caller feeds only the RDB body, so nothing may follow the frame.
* The reader keeps any such bytes pending, and feeding it again would
* trip its resume assertion, so fail the transcode instead. */
if (r == STREAM_PUSH_READER_FRAME_DONE && streamPushReaderHasPendingDecode(&t->reader)) {
t->failed = true;
return C_ERR;
}
break;
}
return C_OK;
Expand Down
51 changes: 51 additions & 0 deletions src/unit/test_compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
extern "C" {
#include "compression.h"
#include "compression_stream.h"
#include "rdb_transcoder.h"
#include "server.h"
#include "zmalloc.h"
}
Expand Down Expand Up @@ -1794,3 +1795,53 @@ TEST(replCompression, pushReaderDrainsBufferedOutputWithoutMoreInput) {
freeReplTestStream(&test_stream);
zfree(payload);
}

/* The disk-based full sync feeds the transcoder only the RDB body, so nothing
* may follow the source frame. Trailing bytes, whether they arrive with the
* frame end or in a later write, must fail the transcode rather than be
* dropped or trip the push reader's resume assertion. */
TEST(CompressionTest, rdbTranscoderRejectsBytesAfterSourceFrame) {
const char *payload = "transcoder-frame-body";
const char *trailer = "TRAILER";
const size_t ntargets = 1 + sizeof(testCompressionAlgos) / sizeof(testCompressionAlgos[0]);

for (compressionAlgo src : testCompressionAlgos) {
DynamicBuf frame;
dynamicBufInit(&frame);
streamWriter w;
ASSERT_EQ(streamWriterInit(&w, src, true, emitToDynamicBuf, &frame), C_OK);
ASSERT_EQ(streamWriterWrite(&w, payload, strlen(payload)), C_OK);
ASSERT_EQ(streamWriterFinish(&w), C_OK);
streamWriterFree(&w);
const size_t frame_len = sdslen((sds)frame.data);
sds with_trailer = sdscatlen(sdsnewlen(frame.data, frame_len), trailer, strlen(trailer));

for (size_t ti = 0; ti < ntargets; ti++) {
compressionAlgo target = ti == 0 ? ALGO_NONE : testCompressionAlgos[ti - 1];
if (target == src) continue; /* Verbatim route never decodes the frame. */
for (bool same_write : {true, false}) {
SCOPED_TRACE(testing::Message() << "src=" << src << " target=" << target
<< " same_write=" << same_write);
DynamicBuf out;
dynamicBufInit(&out);
rdbTranscoder t;
rdbTranscoderInit(&t, target, false, emitToDynamicBuf, &out);
if (same_write) {
EXPECT_EQ(rdbTranscoderWrite(&t, with_trailer, sdslen(with_trailer)), C_ERR);
} else {
/* The trailer spans two writes, as it does when the receive
* loop reads it in more than one chunk. */
ASSERT_EQ(rdbTranscoderWrite(&t, frame.data, frame_len), C_OK);
EXPECT_EQ(rdbTranscoderWrite(&t, trailer, 3), C_ERR);
EXPECT_EQ(rdbTranscoderWrite(&t, trailer + 3, strlen(trailer) - 3), C_ERR);
}
EXPECT_TRUE(t.failed);
EXPECT_EQ(rdbTranscoderFinish(&t), C_ERR);
rdbTranscoderFree(&t);
dynamicBufFree(&out);
}
}
sdsfree(with_trailer);
dynamicBufFree(&frame);
}
}
Loading