PDF Output: Dont dedup images that cannot be uncompressed

Fixes #1856564 [pdf conversion error](https://bugs.launchpad.net/calibre/+bug/1856564)
This commit is contained in:
Kovid Goyal 2019-12-18 10:49:05 +05:30
parent 5ad63e6d9a
commit 4706561f57
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -19,7 +19,11 @@ class Image {
public:
Image(const PdfReference &reference, const PdfObject *o) : buf(NULL), sz(0), width(0), height(0), ref(reference) {
const PdfStream *stream = o->GetStream();
stream->GetFilteredCopy(&buf, &sz);
try {
stream->GetFilteredCopy(&buf, &sz);
} catch(...) {
buf = NULL; sz = -1;
}
const PdfDictionary &dict = o->GetDictionary();
if (dict.HasKey("Width") && dict.GetKey("Width")->IsNumber()) width = dict.GetKey("Width")->GetNumber();
if (dict.HasKey("Height") && dict.GetKey("Height")->IsNumber()) height = dict.GetKey("Height")->GetNumber();
@ -36,7 +40,7 @@ class Image {
}
~Image() noexcept { if (buf) podofo_free(buf); buf = NULL; }
bool operator==(const Image &other) const noexcept {
return other.sz == sz && other.width == width && other.height == height && memcmp(buf, other.buf, sz) == 0;
return other.sz == sz && sz > -1 && other.width == width && other.height == height && memcmp(buf, other.buf, sz) == 0;
}
std::size_t hash() const noexcept { return sz; }
const PdfReference& reference() const noexcept { return ref; }