Skip to content
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

Decompression failures with uncompressable data #141

Closed
nemequ opened this issue Aug 24, 2015 · 2 comments
Closed

Decompression failures with uncompressable data #141

nemequ opened this issue Aug 24, 2015 · 2 comments

Comments

@nemequ
Copy link
Contributor

nemequ commented Aug 24, 2015

Seems to happen with data with a length of a power of two >= 32. 8 and 16 work, 32, 64, 128, and 256 don't. Test case:

#include <stdint.h>
#include <assert.h>

#include "enc/encode.h"
#include "dec/decode.h"

const uint8_t uncompressed[] = {
  0x01, 0x4a, 0x2d, 0x82, 0x59, 0x2f, 0xdd, 0xe6,
  0x4f, 0x69, 0x6c, 0x70, 0x13, 0x87, 0x9f, 0xe4,
  0xd3, 0xb1, 0x9a, 0x86, 0xeb, 0x31, 0xa9, 0x69,
  0x1d, 0x2b, 0x22, 0x60, 0x38, 0xaf, 0xb2, 0x27,
  0xee, 0x48, 0x9e, 0x67, 0x3d, 0x5f, 0xca, 0xfa,
  0x68, 0x74, 0x03, 0x6f, 0x03, 0x5c, 0xcb, 0x45,
  0x1c, 0xfc, 0xc1, 0x4b, 0x1d, 0xb1, 0x2b, 0x7b,
  0x87, 0xf2, 0xf4, 0xea, 0xc4, 0x34, 0x93, 0x75,
  0xb5, 0x45, 0xa0, 0x70, 0x77, 0xe9, 0xe3, 0xe3,
  0xe9, 0xf9, 0x36, 0x80, 0x2c, 0x3b, 0x19, 0xab,
  0x46, 0xe2, 0xeb, 0x16, 0xf9, 0x4c, 0xac, 0x03,
  0x42, 0x8c, 0x25, 0x3a, 0x9e, 0x68, 0xc7, 0x26,
  0xce, 0x45, 0x1f, 0x3f, 0xc6, 0x24, 0x38, 0x01,
  0xb2, 0x1a, 0x4f, 0x25, 0xd3, 0x7c, 0x5f, 0x37,
  0xbc, 0x6b, 0x3d, 0xb1, 0x1d, 0x76, 0xc5, 0xb9,
  0xae, 0xbd, 0x4c, 0x67, 0x87, 0xd9, 0xd0, 0x58,
  0xe9, 0x42, 0x4e, 0x32, 0xbf, 0x83, 0xfd, 0xad,
  0x63, 0x88, 0x7c, 0x9d, 0xd3, 0x25, 0x9e, 0xe0,
  0x44, 0x4a, 0xbf, 0x88, 0xc4, 0x46, 0x24, 0x21,
  0xf3, 0x35, 0xee, 0xa9, 0xc4, 0x6f, 0xdf, 0xe5,
  0xef, 0xc5, 0x13, 0x25, 0x3f, 0x33, 0x1e, 0x54,
  0x45, 0x79, 0xc0, 0x5e, 0x67, 0x4e, 0x7b, 0xa7,
  0xe1, 0xe8, 0x7c, 0xe6, 0x5a, 0x7a, 0x20, 0x4f,
  0x1b, 0xf2, 0xe9, 0x6a, 0x8e, 0xfc, 0x23, 0xfd,
  0x5f, 0x47, 0x24, 0x9c, 0xe4, 0xa9, 0x0c, 0x3d,
  0x8f, 0x9d, 0x81, 0x46, 0x25, 0x2d, 0x43, 0x49,
  0xe2, 0xcc, 0x98, 0x8d, 0x14, 0x2b, 0x17, 0xc2,
  0x1b, 0xd3, 0x03, 0x13, 0x8d, 0x72, 0x76, 0x96,
  0xce, 0x23, 0x93, 0xee, 0x30, 0x7a, 0xe3, 0x74,
  0xb6, 0x28, 0xc4, 0xfc, 0xb6, 0x3e, 0xf9, 0xe0,
  0x9a, 0x88, 0x86, 0x5b, 0xfc, 0xc0, 0x0b, 0xdf,
  0xa4, 0xfb, 0x79, 0x0f, 0x95, 0x12, 0xaf, 0x43
};

int main(int argc, char *argv[]) {
  uint8_t compressed[sizeof(uncompressed) + 4];
  size_t compressed_length = sizeof(compressed);
  uint8_t decompressed[sizeof(uncompressed)];
  size_t decompressed_length = sizeof(decompressed);

  {
    int result;
    brotli::BrotliParams params;
    params.quality = 11;
    params.mode = brotli::BrotliParams::MODE_GENERIC;
    params.enable_transforms = false;

    result = brotli::BrotliCompressBuffer (params,
                       sizeof(uncompressed), uncompressed,
                       &compressed_length, compressed);

    assert (result == 1);

    fprintf (stderr, "Compressed %zu bytes to %zu bytes\n", sizeof(uncompressed), compressed_length);
  }

  {
    BrotliResult result;

    result = BrotliDecompressBuffer (compressed_length, compressed,
                     &decompressed_length, decompressed);

    assert (result == BROTLI_RESULT_SUCCESS);

    fprintf (stderr, "Decompressed %zu bytes to %zu bytes\n", compressed_length, decompressed_length);
  }

  return 0;
}
@nemequ
Copy link
Contributor Author

nemequ commented Aug 26, 2015

Just to be clear, the assertion checking the value returned from BrotliDecompressBuffer fails.

@eustas
Copy link
Collaborator

eustas commented Sep 1, 2015

Fixed in PR #148

@eustas eustas closed this as completed Sep 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants