call BrotliDecoderDecompressStream mutil times, return DICTIONARY #434

Closed
opened 2026-01-29 20:43:49 +00:00 by claunia · 1 comment
Owner

Originally created by @luwenpeng on GitHub (Sep 21, 2022).

example()
{
    int ret = 0;

    const char *indata = (const char *)br_resp_raw_body;
    size_t indata_len = sizeof(br_resp_raw_body);

    const char *part1 = indata;
    const char *part2 = indata + (indata_len / 2);

    size_t part1_len = indata_len - (indata_len / 2);
    size_t part2_len = indata_len / 2;

    char out1[4096] = {0};
    char out2[4096] = {0};
    size_t out1_len = 4096;
    size_t out2_len = 4096;

    BrotliDecoderState *brdec_state = BrotliDecoderCreateInstance(NULL, NULL, NULL);

    // first call return value is NEEDS_MORE_INPUT
    ret = BrotliDecoderDecompressStream(brdec_state, &part1, &part1_len, &out1, &out1_len, 0);

    // second call return value is BROTLI_DECODER_RESULT_ERROR
    ret = BrotliDecoderDecompressStream(brdec_state, &part2, &part2_len, &out2, &out2_len, 0);
}

The data stored in indata is the br-compressed data.
BrotliDecoderDecompressStream will return BROTLI_DECODER_RESULT_ERROR when BrotliDecoderDecompressStream is called multiple times for decompression.

At this time, the errcode obtained by BrotliDecoderErrorCode errcode = BrotliDecoderGetErrorCode(brdec_state); is -12, and the error information obtained by BrotliDecoderErrorString(errcode) is DICTIONARY.

Originally created by @luwenpeng on GitHub (Sep 21, 2022). ``` c example() { int ret = 0; const char *indata = (const char *)br_resp_raw_body; size_t indata_len = sizeof(br_resp_raw_body); const char *part1 = indata; const char *part2 = indata + (indata_len / 2); size_t part1_len = indata_len - (indata_len / 2); size_t part2_len = indata_len / 2; char out1[4096] = {0}; char out2[4096] = {0}; size_t out1_len = 4096; size_t out2_len = 4096; BrotliDecoderState *brdec_state = BrotliDecoderCreateInstance(NULL, NULL, NULL); // first call return value is NEEDS_MORE_INPUT ret = BrotliDecoderDecompressStream(brdec_state, &part1, &part1_len, &out1, &out1_len, 0); // second call return value is BROTLI_DECODER_RESULT_ERROR ret = BrotliDecoderDecompressStream(brdec_state, &part2, &part2_len, &out2, &out2_len, 0); } ``` The data stored in indata is the br-compressed data. BrotliDecoderDecompressStream will return **BROTLI_DECODER_RESULT_ERROR** when BrotliDecoderDecompressStream is called multiple times for decompression. At this time, the errcode obtained by `BrotliDecoderErrorCode errcode = BrotliDecoderGetErrorCode(brdec_state);` is -12, and the error information obtained by `BrotliDecoderErrorString(errcode)` is **DICTIONARY**.
Author
Owner

@eustas commented on GitHub (Sep 21, 2022):

Shouldn't it be:

size_t part1_len = indata_len / 2;
size_t part2_len = indata_len - (indata_len / 2);
@eustas commented on GitHub (Sep 21, 2022): Shouldn't it be: ``` size_t part1_len = indata_len / 2; size_t part2_len = indata_len - (indata_len / 2); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#434