{"action":"closed","issue":{"url":"https://api.github.com/repos/google/gipfeli/issues/6","labels_url":"https://api.github.com/repos/google/gipfeli/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/google/gipfeli/issues/6/comments","events_url":"https://api.github.com/repos/google/gipfeli/issues/6/events","html_url":"https://github.com/google/gipfeli/issues/6","id":119514346,"number":6,"title":"Decompressed data does not match original input","user":{"login":"nemequ","id":1151,"avatar_url":"https://avatars.githubusercontent.com/u/1151?v=3","gravatar_id":"","url":"https://api.github.com/users/nemequ","html_url":"https://github.com/nemequ","followers_url":"https://api.github.com/users/nemequ/followers","following_url":"https://api.github.com/users/nemequ/following{/other_user}","gists_url":"https://api.github.com/users/nemequ/gists{/gist_id}","starred_url":"https://api.github.com/users/nemequ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nemequ/subscriptions","organizations_url":"https://api.github.com/users/nemequ/orgs","repos_url":"https://api.github.com/users/nemequ/repos","events_url":"https://api.github.com/users/nemequ/events{/privacy}","received_events_url":"https://api.github.com/users/nemequ/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-30T15:26:26Z","updated_at":"2015-11-30T17:44:56Z","closed_at":"2015-11-30T17:44:56Z","body":"I'm improving the random-data test case in [Squash](https://github.com/quixdb/squash) to try buffers of random data up to 8 MiB, and I've noticed that Gipfeli starts to fail around a couple hundred KiB due to the decompressed data not matching the input.  An example of problematic input is at http://code.coeusgroup.com/gipfeli-bug (357 KiB)\r\n\r\nTo verify that the issue was in Gipfeli and not Squash, I threw together this test:\r\n\r\n```C\r\n#include <stdio.h>\r\n#include <assert.h>\r\n\r\n#include \"gipfeli.h\"\r\n#include \"stubs-internal.h\"\r\n\r\nint main(int argc, char *argv[]) {\r\n  FILE* input = fopen (argv[1], \"rb\");\r\n  assert (input != NULL);\r\n\r\n  int r = fseek (input, 0, SEEK_END);\r\n  assert (r == 0);\r\n  size_t uncompressed_size;\r\n  {\r\n    long p = ftell (input);\r\n    assert (p > 0);\r\n    uncompressed_size = (size_t) p;\r\n  }\r\n  fseek (input, SEEK_SET, 0);\r\n\r\n  uint8_t* uncompressed = (uint8_t*) malloc (uncompressed_size);\r\n  assert (uncompressed != NULL);\r\n  fread (uncompressed, 1, uncompressed_size, input);\r\n  fclose (input);\r\n  input = NULL;\r\n\r\n  util::compression::Compressor* compressor =\r\n    util::compression::NewGipfeliCompressor();\r\n\r\n  size_t compressed_size = compressor->MaxCompressedLength (uncompressed_size);\r\n  uint8_t* compressed = (uint8_t*) malloc (compressed_size);\r\n\r\n  {\r\n    util::compression::UncheckedByteArraySink sink((char*) compressed);\r\n    util::compression::ByteArraySource source((const char*) uncompressed, uncompressed_size);\r\n\r\n    compressed_size = compressor->CompressStream (&source, &sink);\r\n    fprintf (stderr, \"Compressed %p[%zu] -> %p[%zu]\\n\", uncompressed, uncompressed_size, compressed, compressed_size);\r\n  }\r\n\r\n  {\r\n    std::string compressed_str((const char*) compressed, compressed_size);\r\n\r\n    size_t decompressed_size;\r\n    if (!compressor->GetUncompressedLength (compressed_str, &decompressed_size)) {\r\n      abort ();\r\n    }\r\n\r\n    assert (decompressed_size == uncompressed_size);\r\n    uint8_t* decompressed = (uint8_t*) malloc (decompressed_size);\r\n    assert (decompressed != NULL);\r\n\r\n    util::compression::UncheckedByteArraySink sink((char*) decompressed);\r\n    util::compression::ByteArraySource source((const char*) compressed, compressed_size);\r\n\r\n    if (compressor->UncompressStream (&source, &sink)) {\r\n      fprintf (stderr, \"Decompressed %p[%zu] -> %p[%zu]\\n\", compressed, compressed_size, decompressed, decompressed_size);\r\n    } else {\r\n      fprintf (stderr, \"Failed to decompress.\\n\");\r\n      abort ();\r\n    }\r\n\r\n    int res = memcmp (uncompressed, decompressed, uncompressed_size);\r\n    assert (res == 0);\r\n\r\n    free (decompressed);\r\n  }\r\n\r\n  delete compressor;\r\n  free (compressed);\r\n  free (uncompressed);\r\n\r\n  return 0;\r\n}\r\n```\r\n\r\nJust feed it the name of the uncompressed file as the first argument, it should trigger the issue.  It works for most files, but seems not to like larger blocks of random data."}}