-
Notifications
You must be signed in to change notification settings - Fork 35
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
zLib decoding fails with failed to fill whole buffer #71
Comments
Could you share your TypeScript code that was able to decode the data? I tried decoding the data using Node.js but it failed as follows: > require('zlib')
> zlib.inflateSync(new Uint8Array( [120, 218, 251, 255, 207, 144, 193, 138, 193, 151, 161, 146, 33, 143, 33, 149, 161, 156, 161, 24, 72, 38, 51, 148, 48, 100, 50, 228, 3, 69, 120, 25, 184, 24]))
Uncaught Error: unexpected end of file
at Zlib.zlibOnError [as onerror] (node:zlib:189:17)
at Zlib.callbackTrampoline (node:internal/async_hooks:130:17)
at processChunkSync (node:zlib:457:12)
at zlibBufferSync (node:zlib:178:12)
at Object.syncBufferWrapper [as inflateSync] (node:zlib:792:14)
at REPL41:1:6
at Script.runInThisContext (node:vm:128:12)
at REPLServer.defaultEval (node:repl:570:29)
at bound (node:domain:433:15) {
errno: -5,
code: 'Z_BUF_ERROR'
} I tried with Python3 too, but it got the same error: > import zlib
> >>> x = [120, 218, 251, 255, 207, 144, 193, 138, 193, 151, 161, 146, 33, 143, 33, 149, 161, 156, 161, 24, 72, 38, 51, 148, 48, 100, 50, 228, 3, 69, 120, 25, 184, 24]
>>> y = b''.join(x.to_bytes(1, byteorder='big') for x in x)
>>> zlib.decompress(y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
zlib.error: Error -5 while decompressing data: incomplete or truncated stream |
@sile Sure: this is my TypeScript code: import * as zlib from "zlib";
const inflatedBuffer = zlib.inflateSync(buffer, { finishFlush: zlib.constants.Z_FULL_FLUSH }); This is how I was able to solve your |
It should return
or
if done right |
Using a 4 year old crate called |
Thank you. After some investigation, it seems that the input data is somewhat corrupted, so unexpected EOF error is raised without |
Added let encoded_data = [
120, 218, 251, 255, 207, 144, 193, 138, 193, 151, 161, 146, 33, 143, 33, 149, 161, 156,
161, 24, 72, 38, 51, 148, 48, 100, 50, 228, 3, 69, 120, 25, 184, 24,
];
let mut decoder = Decoder::new(&encoded_data[..]).unwrap();
let mut buf = Vec::new();
let result = decoder.read_to_end(&mut buf);
assert!(result.is_err());
buf.extend_from_slice(decoder.unread_decoded_data());
let decoded_data = [
255, 254, 49, 0, 58, 0, 77, 0, 121, 0, 110, 0, 101, 0, 119, 0, 115, 0, 101, 0, 99, 0,
116, 0, 105, 0, 111, 0, 110, 0, 13, 0, 10,
];
assert_eq!(buf, decoded_data); |
I'm trying to decode a zLib
Vec<u8>
which works fine in C# & TypeScript but I'm trying it in Rust and it instantly fails with that error message.This is the code I use:
Buffer:
[120, 218, 251, 255, 207, 144, 193, 138, 193, 151, 161, 146, 33, 143, 33, 149, 161, 156, 161, 24, 72, 38, 51, 148, 48, 100, 50, 228, 3, 69, 120, 25, 184, 24]
The text was updated successfully, but these errors were encountered: