@@ -167,6 +167,26 @@ void checkOverflow(std::unique_ptr<MessageCompressorBase> compressor) {
167167 compressor->decompressData (tooSmallRange, DataRange (scratch.data (), scratch.size ())));
168168}
169169
170+ void checkUndersize (const Message& compressedMsg,
171+ std::unique_ptr<MessageCompressorBase> compressor) {
172+ MessageCompressorRegistry registry;
173+ const auto compressorName = compressor->getName ();
174+
175+ std::vector<std::string> compressorList = {compressorName};
176+ registry.setSupportedCompressors (std::move (compressorList));
177+ registry.registerImplementation (std::move (compressor));
178+ registry.finalizeSupportedCompressors ().transitional_ignore ();
179+
180+ MessageCompressorManager mgr (®istry);
181+ BSONObjBuilder negotiatorOut;
182+ auto negotiator = BSON (" isMaster" << 1 << " compression" << BSON_ARRAY (compressorName));
183+ mgr.serverNegotiate (negotiator, &negotiatorOut);
184+ checkNegotiationResult (negotiatorOut.done (), {compressorName});
185+
186+ auto swm = mgr.decompressMessage (compressedMsg);
187+ ASSERT_EQ (ErrorCodes::BadValue, swm.getStatus ());
188+ }
189+
170190Message buildMessage () {
171191 const auto data = std::string{" Hello, world!" };
172192 const auto bufferSize = MsgData::MsgDataHeaderSize + data.size ();
@@ -252,6 +272,52 @@ TEST(ZstdMessageCompressor, Overflow) {
252272 checkOverflow (std::make_unique<ZstdMessageCompressor>());
253273}
254274
275+ TEST (ZlibMessageCompressor, Mismatch) {
276+ checkOverflow (std::make_unique<ZlibMessageCompressor>());
277+ }
278+
279+ TEST (SnappyMessageCompressor, Undersize) {
280+ std::vector<std::uint8_t > payload = {
281+ 0x41 , 0x0 , 0x0 , 0x0 , 0xad , 0xde , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xdc ,
282+ 0x7 , 0x0 , 0x0 , 0xdd , 0x7 , 0x0 , 0x0 , 0x0 , 0x20 , 0x0 , 0x0 , 0x1 , 0x27 ,
283+ 0x0 , 0x0 , 0x1 , 0x1 , 0x84 , 0xfb , 0x1f , 0x0 , 0x0 , 0x5 , 0x5f , 0x69 , 0x64 ,
284+ 0x0 , 0x0 , 0x10 , 0x0 , 0x0 , 0x0 , 0x48 , 0x45 , 0x41 , 0x50 , 0x4c , 0x45 , 0x41 ,
285+ 0x4b , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 };
286+
287+
288+ auto buffer = SharedBuffer::allocate (payload.size ());
289+ std::copy (payload.begin (), payload.end (), buffer.get ());
290+
291+ checkUndersize (Message (buffer), std::make_unique<SnappyMessageCompressor>());
292+ }
293+
294+ TEST (ZlibMessageCompressor, Undersize) {
295+ std::vector<std::uint8_t > payload = {
296+ 0x3c , 0x00 , 0x00 , 0x00 , 0xad , 0xde , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xdc , 0x07 , 0x00 ,
297+ 0x00 , 0xdd , 0x07 , 0x00 , 0x00 , 0x00 , 0x20 , 0x00 , 0x00 , 0x02 , 0x78 , 0xda , 0x63 , 0x60 , 0x00 ,
298+ 0x82 , 0xdf , 0xf2 , 0x0c , 0x0c , 0xac , 0xf1 , 0x99 , 0x29 , 0x0c , 0x0c , 0x02 , 0x40 , 0x9e , 0x87 ,
299+ 0xab , 0x63 , 0x80 , 0x8f , 0xab , 0xa3 , 0x37 , 0x03 , 0x12 , 0x00 , 0x00 , 0x6d , 0x26 , 0x04 , 0x97 };
300+
301+ auto buffer = SharedBuffer::allocate (payload.size ());
302+ std::copy (payload.begin (), payload.end (), buffer.get ());
303+
304+ checkUndersize (Message (buffer), std::make_unique<ZlibMessageCompressor>());
305+ }
306+
307+ TEST (ZstdMessageCompressor, Undersize) {
308+ std::vector<std::uint8_t > payload = {
309+ 0x44 , 0x0 , 0x0 , 0x0 , 0xad , 0xde , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xdc , 0x7 ,
310+ 0x0 , 0x0 , 0xdd , 0x7 , 0x0 , 0x0 , 0x0 , 0x20 , 0x0 , 0x0 , 0x3 , 0x28 , 0xb5 , 0x2f ,
311+ 0xfd , 0x20 , 0x27 , 0x15 , 0x1 , 0x0 , 0xe0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xfb , 0x1f ,
312+ 0x0 , 0x0 , 0x5 , 0x5f , 0x69 , 0x64 , 0x0 , 0x0 , 0x10 , 0x0 , 0x0 , 0x0 , 0x48 , 0x45 ,
313+ 0x41 , 0x50 , 0x4c , 0x45 , 0x41 , 0x4b , 0x0 , 0x1 , 0x0 , 0x18 , 0xc0 , 0x9 };
314+
315+ auto buffer = SharedBuffer::allocate (payload.size ());
316+ std::copy (payload.begin (), payload.end (), buffer.get ());
317+
318+ checkUndersize (Message (buffer), std::make_unique<ZstdMessageCompressor>());
319+ }
320+
255321TEST (MessageCompressorManager, SERVER_28008) {
256322
257323 // Create a client and server that will negotiate the same compressors,
0 commit comments