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)
- zstd fails to process some filenames on Windows [we need a hero] HOT 3
- We need a ZStd JavaScript library HOT 1
- Compiler warnings present when integrated with Swift Package Manager
- will zstd get nvcomp acceleration or a gpu support like g-brotli? HOT 1
- How can I change the window size? HOT 1
- Increase minimum C standard from C89/C90 to C11 HOT 3
- New zstd 1.5.5 version is two times slower in compression speed than older 1.4.5 version HOT 11
- ZSTD with T option does not scale on multicore CPUs HOT 7
- Question about FSE Huffman literal part
- C++ Builder and mem.h ambiguity HOT 7
- Reducing DCtx Size for Embedded Systems (like esp32) HOT 2
- Automatic code formatting? HOT 1
- No `uncompressed` and `ratio` information in `zstd --list` output if the zstd file is created via pipe HOT 3
- lz4 "legacy" format support HOT 1
- Add common file types that are compressed to ' --exclude-compressed' HOT 3
- windows
- compressing files containing multiple similar portions HOT 5
- Using ZSTD_compressBound for Streaming Input HOT 4
- head file not found HOT 1
- ZSTD-1.5.2 compress Segmentation fault HOT 4
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.