Comments (4)
Hi Luben
Yes that's correct. Zstd is not yet protected against buffer overflow, hence not ready for production usage.
The first error surprised me : ZSTD_compress() is supposed to be protected against overflow, because it requires maxDstSize >= ZSTD_compressBound(rawSize).
But looking at the code, it seems this protection was removed during one of the refactoring exercise. Not a huge deal, since this protection is supposed to be temporary, but as long as the definitive solution is not avaiable, it should stay around, so I'll update the code to re-instate that condition.
ZSTD_decompress(), on the other hand, is more difficult to protect. So it will require a bit more time to get there.
Best Regards
from zstd.
Latest version in "dev" branch seems to correctly prevent buffer overflow during compression.
On the other hand, decompression side still needs to be done.
For the record, here is my slightly modified version of your very useful test program :
#include <stdio.h>
#include <stdlib.h>
#include "zstd.h"
#define SAMPLE_SIZE 1000
#define CBUFF_SIZE (ZSTD_compressBound(SAMPLE_SIZE))
#define DBUFF_SIZE (SAMPLE_SIZE-100)
int main(int argc, char **argv ) {
char *raw = (char *)malloc(SAMPLE_SIZE);
char compressed[CBUFF_SIZE];
char decompressed[DBUFF_SIZE];
size_t i, ccode, dcode;
// fill it with ones
for (i=0; i<1000; i++) raw[i] = 1;
ccode = ZSTD_compress(compressed, 20, raw, SAMPLE_SIZE);
printf("Max 20 : Compression code %zu\n", ccode); /* will correctly return an error code */
ccode = ZSTD_compress(compressed, CBUFF_SIZE, raw, SAMPLE_SIZE);
printf("Max CBUFF_SIZE : Compression code %zu\n", ccode);
dcode = ZSTD_decompress(decompressed, DBUFF_SIZE, compressed, ccode); /* will smash the stack */
printf("Decompression code %zu\n", dcode);
return 0;
}
from zstd.
By the way, the decoding side of this issue seems technically the same as #11. Maybe we should fold both issues into one.
from zstd.
Merged this issue into #11
from zstd.
Related Issues (20)
- MSVC CMake build failed on v1.5.6
- v1.5.6 Windows binary downloads are double zipped HOT 4
- Raise version's in win32 binaries header HOT 3
- Why was the new release 1.5.6 removed? HOT 15
- long file names are cut off in output HOT 3
- Should zstd check archive consistency before overwriting files? HOT 1
- Should zstd delete incomplete archives? HOT 5
- 32-bit x86 build failure with 1.5.6 HOT 3
- v1.5.6 breaks 32-bit Windows clang-cl build HOT 3
- Decompress multiple zstaa backups on FAT32 drives HOT 4
- Replication of bug #3517 HOT 29
- Separate dictionary references to enable dictionary usage for any combination of window size and content size HOT 1
- Decompression speed regression in zstd 1.5.6 (win)
- Embed hash of raw dictionary in compressed resource (optionally) HOT 4
- Decompression crash after upgrading from zstd 1.4.5 to 1.5.6 HOT 12
- Missing check on failed allocation leads to NULL-ptr dereference HOT 1
- libzstd.lib missed in package, also VC sample seems include wrong mem.h or ambigious including!
- Environment variable for --memory HOT 2
- Improve misleading wording in the streaming decompression howto HOT 2
- erro
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zstd.