-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpp bombs test #17376
cpp bombs test #17376
Conversation
…into amammad-cpp-bombs
…tion, fix gzopen additional flow step thanks to @jketema
…nto amammad-cpp-bombs
…ave enough time as the library is not popular enough. add tests for minizip lib
zstd is not finilized
…not in the priority
QHelp previews: cpp/ql/src/experimental/Security/CWE/CWE-409/DecompressionBombs.qhelpUser-controlled file decompressionExtracting Compressed files with any compression algorithm like gzip can cause denial of service attacks. Attackers can compress a huge file consisting of repeated similiar bytes into a small compressed file. RecommendationWhen you want to decompress a user-provided compressed file you must be careful about the decompression ratio or read these files within a loop byte by byte to be able to manage the decompressed size in each cycle of the loop. ExampleReading an uncompressed Gzip file within a loop and check for a threshold size in each cycle. #include "zlib.h"
void SafeGzread(gzFile inFileZ) {
const int MAX_READ = 1024 * 1024 * 4;
const int BUFFER_SIZE = 8192;
unsigned char unzipBuffer[BUFFER_SIZE];
unsigned int unzippedBytes;
unsigned int totalRead = 0;
while (true) {
unzippedBytes = gzread(inFileZ, unzipBuffer, BUFFER_SIZE);
totalRead += unzippedBytes;
if (unzippedBytes <= 0) {
break;
}
if (totalRead > MAX_READ) {
// Possible decompression bomb, stop processing.
break;
} else {
// process buffer
}
}
}
The following example is unsafe, as we do not check the uncompressed size. #include "zlib.h"
void UnsafeGzread(gzFile inFileZ) {
const int BUFFER_SIZE = 8192;
unsigned char unzipBuffer[BUFFER_SIZE];
unsigned int unzippedBytes;
while (true) {
unzippedBytes = gzread(inFileZ, unzipBuffer, BUFFER_SIZE);
if (unzippedBytes <= 0) {
break;
}
// process buffer
}
}
References
|
One good and one bad example suffices to get the point across, and makes the help more readable. The examples also do not have to be complete.
There are no barriers, so the query as is will flag up any use of the identified functions.
No description provided.