Restore the bytes overwritten by the tail after inflation (#1653)

This commit is contained in:
Sean Oxley
2023-09-04 17:04:26 +09:00
committed by GitHub
parent 3bb917da2e
commit f1b10ed221
+9 -1
View File
@@ -245,9 +245,14 @@ struct InflationStream {
}
#endif
/* Save off the bytes we're about to overwrite */
char* tailLocation = (char*)compressed.data() + compressed.length();
char preTailBytes[4];
memcpy(preTailBytes, tailLocation, 4);
/* Append tail to chunk */
unsigned char tail[4] = {0x00, 0x00, 0xff, 0xff};
memcpy((char *)compressed.data() + compressed.length(), tail, 4);
memcpy(tailLocation, tail, 4);
compressed = {compressed.data(), compressed.length() + 4};
/* We clear this one here, could be done better */
@@ -275,6 +280,9 @@ struct InflationStream {
inflateReset(&inflationStream);
}
/* Restore the bytes we used for the tail */
memcpy(tailLocation, preTailBytes, 4);
if ((err != Z_BUF_ERROR && err != Z_OK) || zlibContext->dynamicInflationBuffer.length() > maxPayloadLength) {
return std::nullopt;
}