mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-02-26 13:52:49 +01:00
Clean up some compiler warnings.
This commit is contained in:
parent
6e2e4bbcc6
commit
1237599dea
@ -241,7 +241,7 @@ _pdfioCryptoAESEncrypt(
|
|||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
// Pad the final buffer with (16 - len)...
|
// Pad the final buffer with (16 - len)...
|
||||||
memset(outbuffer + len, 16 - len, 16 - len);
|
memset(outbuffer + len, (int)(16 - len), 16 - len);
|
||||||
|
|
||||||
xor_with_iv(outbuffer, iv);
|
xor_with_iv(outbuffer, iv);
|
||||||
cipher((state_t*)outbuffer, ctx);
|
cipher((state_t*)outbuffer, ctx);
|
||||||
|
@ -98,7 +98,7 @@ _pdfioFileFlush(pdfio_file_t *pdf) // I - PDF file
|
|||||||
if (!write_buffer(pdf, pdf->buffer, (size_t)(pdf->bufptr - pdf->buffer)))
|
if (!write_buffer(pdf, pdf->buffer, (size_t)(pdf->bufptr - pdf->buffer)))
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
pdf->bufpos += pdf->bufptr - pdf->buffer;
|
pdf->bufpos += (off_t)(pdf->bufptr - pdf->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
pdf->bufptr = pdf->buffer;
|
pdf->bufptr = pdf->buffer;
|
||||||
@ -216,7 +216,7 @@ _pdfioFilePeek(pdfio_file_t *pdf, // I - PDF file
|
|||||||
PDFIO_DEBUG("_pdfioFilePeek: Sliding buffer, total=%ld\n", (long)total);
|
PDFIO_DEBUG("_pdfioFilePeek: Sliding buffer, total=%ld\n", (long)total);
|
||||||
|
|
||||||
memmove(pdf->buffer, pdf->bufptr, total);
|
memmove(pdf->buffer, pdf->bufptr, total);
|
||||||
pdf->bufpos += pdf->bufptr - pdf->buffer;
|
pdf->bufpos += (off_t)(pdf->bufptr - pdf->buffer);
|
||||||
pdf->bufptr = pdf->buffer;
|
pdf->bufptr = pdf->buffer;
|
||||||
pdf->bufend = pdf->buffer + total;
|
pdf->bufend = pdf->buffer + total;
|
||||||
|
|
||||||
@ -317,14 +317,14 @@ _pdfioFileRead(pdfio_file_t *pdf, // I - PDF file
|
|||||||
// Advance current position in file as needed...
|
// Advance current position in file as needed...
|
||||||
if (pdf->bufend)
|
if (pdf->bufend)
|
||||||
{
|
{
|
||||||
pdf->bufpos += pdf->bufend - pdf->buffer;
|
pdf->bufpos += (off_t)(pdf->bufend - pdf->buffer);
|
||||||
pdf->bufptr = pdf->bufend = NULL;
|
pdf->bufptr = pdf->bufend = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read directly from the file...
|
// Read directly from the file...
|
||||||
if ((rbytes = read_buffer(pdf, bufptr, bytes)) > 0)
|
if ((rbytes = read_buffer(pdf, bufptr, bytes)) > 0)
|
||||||
{
|
{
|
||||||
pdf->bufpos += rbytes;
|
pdf->bufpos += (off_t)rbytes;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (rbytes < 0 && (errno == EINTR || errno == EAGAIN))
|
else if (rbytes < 0 && (errno == EINTR || errno == EAGAIN))
|
||||||
@ -361,14 +361,14 @@ _pdfioFileSeek(pdfio_file_t *pdf, // I - PDF file
|
|||||||
// Adjust offset for relative seeks...
|
// Adjust offset for relative seeks...
|
||||||
if (whence == SEEK_CUR)
|
if (whence == SEEK_CUR)
|
||||||
{
|
{
|
||||||
offset += pdf->bufpos + (pdf->bufptr - pdf->buffer);
|
offset += pdf->bufpos + (off_t)(pdf->bufptr - pdf->buffer);
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdf->mode == _PDFIO_MODE_READ)
|
if (pdf->mode == _PDFIO_MODE_READ)
|
||||||
{
|
{
|
||||||
// Reading, see if we already have the data we need...
|
// Reading, see if we already have the data we need...
|
||||||
if (whence != SEEK_END && offset >= pdf->bufpos && pdf->bufend && offset < (pdf->bufpos + pdf->bufend - pdf->buffer))
|
if (whence != SEEK_END && offset >= pdf->bufpos && pdf->bufend && offset < (off_t)(pdf->bufpos + pdf->bufend - pdf->buffer))
|
||||||
{
|
{
|
||||||
// Yes, seek within existing buffer...
|
// Yes, seek within existing buffer...
|
||||||
pdf->bufptr = pdf->buffer + (offset - pdf->bufpos);
|
pdf->bufptr = pdf->buffer + (offset - pdf->bufpos);
|
||||||
|
@ -322,7 +322,7 @@ pdfioArrayCreateColorFromPalette(
|
|||||||
|
|
||||||
pdfioArrayAppendName(indexed_color, "Indexed");
|
pdfioArrayAppendName(indexed_color, "Indexed");
|
||||||
pdfioArrayAppendName(indexed_color, "DeviceRGB");
|
pdfioArrayAppendName(indexed_color, "DeviceRGB");
|
||||||
pdfioArrayAppendNumber(indexed_color, num_colors - 1);
|
pdfioArrayAppendNumber(indexed_color, (double)(num_colors - 1));
|
||||||
pdfioArrayAppendBinary(indexed_color, colors, num_colors * 3);
|
pdfioArrayAppendBinary(indexed_color, colors, num_colors * 3);
|
||||||
|
|
||||||
return (indexed_color);
|
return (indexed_color);
|
||||||
@ -1814,14 +1814,14 @@ pdfioFileCreateFontObjFromFile(
|
|||||||
if ((i - start) > 1)
|
if ((i - start) > 1)
|
||||||
{
|
{
|
||||||
// Encode a repeating sequence...
|
// Encode a repeating sequence...
|
||||||
pdfioArrayAppendNumber(w_array, start);
|
pdfioArrayAppendNumber(w_array, (double)start);
|
||||||
pdfioArrayAppendNumber(w_array, i - 1);
|
pdfioArrayAppendNumber(w_array, (double)(i - 1));
|
||||||
pdfioArrayAppendNumber(w_array, w0);
|
pdfioArrayAppendNumber(w_array, w0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Encode a non-repeating sequence...
|
// Encode a non-repeating sequence...
|
||||||
pdfioArrayAppendNumber(w_array, start);
|
pdfioArrayAppendNumber(w_array, (double)start);
|
||||||
|
|
||||||
if ((temp_array = pdfioArrayCreate(pdf)) == NULL)
|
if ((temp_array = pdfioArrayCreate(pdf)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
@ -1946,7 +1946,7 @@ pdfioFileCreateICCObjFromData(
|
|||||||
if ((dict = pdfioDictCreate(pdf)) == NULL)
|
if ((dict = pdfioDictCreate(pdf)) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
pdfioDictSetNumber(dict, "N", num_colors);
|
pdfioDictSetNumber(dict, "N", (double)num_colors);
|
||||||
pdfioDictSetName(dict, "Filter", "FlateDecode");
|
pdfioDictSetName(dict, "Filter", "FlateDecode");
|
||||||
|
|
||||||
if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL)
|
if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL)
|
||||||
@ -2012,7 +2012,7 @@ pdfioFileCreateICCObjFromFile(
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
pdfioDictSetNumber(dict, "N", num_colors);
|
pdfioDictSetNumber(dict, "N", (double)num_colors);
|
||||||
pdfioDictSetName(dict, "Filter", "FlateDecode");
|
pdfioDictSetName(dict, "Filter", "FlateDecode");
|
||||||
|
|
||||||
if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL)
|
if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL)
|
||||||
@ -2095,8 +2095,8 @@ pdfioFileCreateImageObjFromData(
|
|||||||
pdfioDictSetName(dict, "Type", "XObject");
|
pdfioDictSetName(dict, "Type", "XObject");
|
||||||
pdfioDictSetName(dict, "Subtype", "Image");
|
pdfioDictSetName(dict, "Subtype", "Image");
|
||||||
pdfioDictSetBoolean(dict, "Interpolate", interpolate);
|
pdfioDictSetBoolean(dict, "Interpolate", interpolate);
|
||||||
pdfioDictSetNumber(dict, "Width", width);
|
pdfioDictSetNumber(dict, "Width", (double)width);
|
||||||
pdfioDictSetNumber(dict, "Height", height);
|
pdfioDictSetNumber(dict, "Height", (double)height);
|
||||||
pdfioDictSetNumber(dict, "BitsPerComponent", 8);
|
pdfioDictSetNumber(dict, "BitsPerComponent", 8);
|
||||||
|
|
||||||
if (color_data)
|
if (color_data)
|
||||||
@ -2539,7 +2539,7 @@ copy_jpeg(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy from the file buffer to the ICC buffer
|
// Copy from the file buffer to the ICC buffer
|
||||||
if ((bytes = bufend - bufptr) > length)
|
if ((bytes = bufend - bufptr) > (ssize_t)length)
|
||||||
bytes = (ssize_t)length;
|
bytes = (ssize_t)length;
|
||||||
|
|
||||||
memcpy(icc_data + icc_datalen, bufptr, bytes);
|
memcpy(icc_data + icc_datalen, bufptr, bytes);
|
||||||
@ -2566,7 +2566,7 @@ copy_jpeg(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
bytes = bufend - bufptr;
|
bytes = bufend - bufptr;
|
||||||
|
|
||||||
if (length > bytes)
|
if (length > (size_t)bytes)
|
||||||
{
|
{
|
||||||
// Consume everything we have and grab more...
|
// Consume everything we have and grab more...
|
||||||
length -= (size_t)bytes;
|
length -= (size_t)bytes;
|
||||||
@ -2591,7 +2591,10 @@ copy_jpeg(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (width == 0 || height == 0 || (num_colors != 1 && num_colors != 3))
|
if (width == 0 || height == 0 || (num_colors != 1 && num_colors != 3))
|
||||||
return (NULL);
|
{
|
||||||
|
_pdfioFileError(dict->pdf, "Unable to find JPEG dimensions or image data.");
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
// Create the image object...
|
// Create the image object...
|
||||||
pdfioDictSetNumber(dict, "Width", width);
|
pdfioDictSetNumber(dict, "Width", width);
|
||||||
@ -3567,9 +3570,9 @@ create_image(
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
pdfioDictSetNumber(decode, "BitsPerComponent", depth);
|
pdfioDictSetNumber(decode, "BitsPerComponent", (double)depth);
|
||||||
pdfioDictSetNumber(decode, "Colors", 1);
|
pdfioDictSetNumber(decode, "Colors", 1);
|
||||||
pdfioDictSetNumber(decode, "Columns", width);
|
pdfioDictSetNumber(decode, "Columns", (double)width);
|
||||||
pdfioDictSetNumber(decode, "Predictor", _PDFIO_PREDICTOR_PNG_AUTO);
|
pdfioDictSetNumber(decode, "Predictor", _PDFIO_PREDICTOR_PNG_AUTO);
|
||||||
pdfioDictSetDict(mask_dict, "DecodeParms", decode);
|
pdfioDictSetDict(mask_dict, "DecodeParms", decode);
|
||||||
|
|
||||||
@ -3619,9 +3622,9 @@ create_image(
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
pdfioDictSetNumber(decode, "BitsPerComponent", depth);
|
pdfioDictSetNumber(decode, "BitsPerComponent", (double)depth);
|
||||||
pdfioDictSetNumber(decode, "Colors", num_colors);
|
pdfioDictSetNumber(decode, "Colors", (double)num_colors);
|
||||||
pdfioDictSetNumber(decode, "Columns", width);
|
pdfioDictSetNumber(decode, "Columns", (double)width);
|
||||||
pdfioDictSetNumber(decode, "Predictor", _PDFIO_PREDICTOR_PNG_AUTO);
|
pdfioDictSetNumber(decode, "Predictor", _PDFIO_PREDICTOR_PNG_AUTO);
|
||||||
pdfioDictSetDict(dict, "DecodeParms", decode);
|
pdfioDictSetDict(dict, "DecodeParms", decode);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Cryptographic support functions for PDFio.
|
// Cryptographic support functions for PDFio.
|
||||||
//
|
//
|
||||||
// Copyright © 2021-2023 by Michael R Sweet.
|
// Copyright © 2021-2025 by Michael R Sweet.
|
||||||
//
|
//
|
||||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||||
// information.
|
// information.
|
||||||
@ -466,6 +466,7 @@ _pdfioCryptoMakeReader(
|
|||||||
|
|
||||||
if (memcmp(pdf->password, pdf_user_key, 32) && memcmp(own_user_key, pdf_user_key, 16))
|
if (memcmp(pdf->password, pdf_user_key, 32) && memcmp(own_user_key, pdf_user_key, 16))
|
||||||
{
|
{
|
||||||
|
_pdfioFileError(pdf, "Unable to unlock file.");
|
||||||
*ivlen = 0;
|
*ivlen = 0;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -483,6 +484,7 @@ _pdfioCryptoMakeReader(
|
|||||||
switch (pdf->encryption)
|
switch (pdf->encryption)
|
||||||
{
|
{
|
||||||
default :
|
default :
|
||||||
|
_pdfioFileError(pdf, "Unsupported encryption algorithm.");
|
||||||
*ivlen = 0;
|
*ivlen = 0;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
|
14
pdfio-file.c
14
pdfio-file.c
@ -1799,7 +1799,7 @@ load_xref(
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pdfioFileSeek(pdf, line_offset + ptr + 3 - line, SEEK_SET) < 0)
|
if (_pdfioFileSeek(pdf, line_offset + (off_t)(ptr + 3 - line), SEEK_SET) < 0)
|
||||||
{
|
{
|
||||||
_pdfioFileError(pdf, "Unable to seek to xref object %lu %u.", (unsigned long)number, (unsigned)generation);
|
_pdfioFileError(pdf, "Unable to seek to xref object %lu %u.", (unsigned long)number, (unsigned)generation);
|
||||||
return (false);
|
return (false);
|
||||||
@ -1941,7 +1941,7 @@ load_xref(
|
|||||||
if (w[0] == 0 || buffer[0] == 1)
|
if (w[0] == 0 || buffer[0] == 1)
|
||||||
{
|
{
|
||||||
// Location of object...
|
// Location of object...
|
||||||
current->offset = offset;
|
current->offset = (off_t)offset;
|
||||||
}
|
}
|
||||||
else if (number != offset)
|
else if (number != offset)
|
||||||
{
|
{
|
||||||
@ -1978,7 +1978,7 @@ load_xref(
|
|||||||
else if (!current)
|
else if (!current)
|
||||||
{
|
{
|
||||||
// Add this object...
|
// Add this object...
|
||||||
if (!add_obj(pdf, (size_t)number, (unsigned short)generation, offset))
|
if (!add_obj(pdf, (size_t)number, (unsigned short)generation, (off_t)offset))
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2105,7 +2105,7 @@ load_xref(
|
|||||||
if (pdfioFileFindObj(pdf, (size_t)number))
|
if (pdfioFileFindObj(pdf, (size_t)number))
|
||||||
continue; // Don't replace newer object...
|
continue; // Don't replace newer object...
|
||||||
|
|
||||||
if (!add_obj(pdf, (size_t)number, (unsigned short)generation, offset))
|
if (!add_obj(pdf, (size_t)number, (unsigned short)generation, (off_t)offset))
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2361,7 +2361,7 @@ write_pages(pdfio_file_t *pdf) // I - PDF file
|
|||||||
for (i = 0; i < pdf->num_pages; i ++)
|
for (i = 0; i < pdf->num_pages; i ++)
|
||||||
pdfioArrayAppendObj(kids, pdf->pages[i]);
|
pdfioArrayAppendObj(kids, pdf->pages[i]);
|
||||||
|
|
||||||
pdfioDictSetNumber(pdf->pages_obj->value.value.dict, "Count", pdf->num_pages);
|
pdfioDictSetNumber(pdf->pages_obj->value.value.dict, "Count", (double)pdf->num_pages);
|
||||||
pdfioDictSetArray(pdf->pages_obj->value.value.dict, "Kids", kids);
|
pdfioDictSetArray(pdf->pages_obj->value.value.dict, "Kids", kids);
|
||||||
|
|
||||||
// Write the Pages object...
|
// Write the Pages object...
|
||||||
@ -2438,7 +2438,7 @@ write_trailer(pdfio_file_t *pdf) // I - PDF file
|
|||||||
}
|
}
|
||||||
|
|
||||||
pdfioDictSetName(xref_dict, "Type", "XRef");
|
pdfioDictSetName(xref_dict, "Type", "XRef");
|
||||||
pdfioDictSetNumber(xref_dict, "Size", pdf->num_objs + 2);
|
pdfioDictSetNumber(xref_dict, "Size", (double)(pdf->num_objs + 2));
|
||||||
pdfioDictSetArray(xref_dict, "W", w_array);
|
pdfioDictSetArray(xref_dict, "W", w_array);
|
||||||
pdfioDictSetName(xref_dict, "Filter", "FlateDecode");
|
pdfioDictSetName(xref_dict, "Filter", "FlateDecode");
|
||||||
pdfioDictSetObj(xref_dict, "Info", pdf->info_obj);
|
pdfioDictSetObj(xref_dict, "Info", pdf->info_obj);
|
||||||
@ -2586,7 +2586,7 @@ write_trailer(pdfio_file_t *pdf) // I - PDF file
|
|||||||
pdfioDictSetArray(pdf->trailer_dict, "ID", pdf->id_array);
|
pdfioDictSetArray(pdf->trailer_dict, "ID", pdf->id_array);
|
||||||
pdfioDictSetObj(pdf->trailer_dict, "Info", pdf->info_obj);
|
pdfioDictSetObj(pdf->trailer_dict, "Info", pdf->info_obj);
|
||||||
pdfioDictSetObj(pdf->trailer_dict, "Root", pdf->root_obj);
|
pdfioDictSetObj(pdf->trailer_dict, "Root", pdf->root_obj);
|
||||||
pdfioDictSetNumber(pdf->trailer_dict, "Size", pdf->num_objs + 1);
|
pdfioDictSetNumber(pdf->trailer_dict, "Size", (double)(pdf->num_objs + 1));
|
||||||
|
|
||||||
if (!_pdfioDictWrite(pdf->trailer_dict, NULL, NULL))
|
if (!_pdfioDictWrite(pdf->trailer_dict, NULL, NULL))
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// PDF stream functions for PDFio.
|
// PDF stream functions for PDFio.
|
||||||
//
|
//
|
||||||
// Copyright © 2021-2024 by Michael R Sweet.
|
// Copyright © 2021-2025 by Michael R Sweet.
|
||||||
//
|
//
|
||||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||||
// information.
|
// information.
|
||||||
@ -140,7 +140,7 @@ pdfioStreamClose(pdfio_stream_t *st) // I - Stream
|
|||||||
// Update the length as needed...
|
// Update the length as needed...
|
||||||
if (st->length_obj)
|
if (st->length_obj)
|
||||||
{
|
{
|
||||||
st->length_obj->value.value.number = st->obj->stream_length;
|
st->length_obj->value.value.number = (double)st->obj->stream_length;
|
||||||
pdfioObjClose(st->length_obj);
|
pdfioObjClose(st->length_obj);
|
||||||
}
|
}
|
||||||
else if (st->obj->length_offset)
|
else if (st->obj->length_offset)
|
||||||
@ -440,14 +440,14 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
|
|
||||||
if ((st->remaining = pdfioObjGetLength(obj)) == 0)
|
if ((st->remaining = pdfioObjGetLength(obj)) == 0)
|
||||||
{
|
{
|
||||||
free(st);
|
_pdfioFileError(obj->pdf, "No stream data.");
|
||||||
return (NULL);
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pdfioFileSeek(st->pdf, obj->stream_offset, SEEK_SET) != obj->stream_offset)
|
if (_pdfioFileSeek(st->pdf, obj->stream_offset, SEEK_SET) != obj->stream_offset)
|
||||||
{
|
{
|
||||||
free(st);
|
_pdfioFileError(obj->pdf, "Unable to seek to stream data.");
|
||||||
return (NULL);
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
type = pdfioObjGetType(obj);
|
type = pdfioObjGetType(obj);
|
||||||
@ -460,11 +460,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
ivlen = (size_t)_pdfioFilePeek(st->pdf, iv, sizeof(iv));
|
ivlen = (size_t)_pdfioFilePeek(st->pdf, iv, sizeof(iv));
|
||||||
|
|
||||||
if ((st->crypto_cb = _pdfioCryptoMakeReader(st->pdf, obj, &st->crypto_ctx, iv, &ivlen)) == NULL)
|
if ((st->crypto_cb = _pdfioCryptoMakeReader(st->pdf, obj, &st->crypto_ctx, iv, &ivlen)) == NULL)
|
||||||
{
|
goto error;
|
||||||
// TODO: Add error message?
|
|
||||||
free(st);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
PDFIO_DEBUG("_pdfioStreamOpen: ivlen=%d\n", (int)ivlen);
|
PDFIO_DEBUG("_pdfioStreamOpen: ivlen=%d\n", (int)ivlen);
|
||||||
if (ivlen > 0)
|
if (ivlen > 0)
|
||||||
@ -495,8 +491,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
{
|
{
|
||||||
// TODO: Implement compound filters...
|
// TODO: Implement compound filters...
|
||||||
_pdfioFileError(st->pdf, "Unsupported compound stream filter.");
|
_pdfioFileError(st->pdf, "Unsupported compound stream filter.");
|
||||||
free(st);
|
goto error;
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No filter, read as-is...
|
// No filter, read as-is...
|
||||||
@ -529,8 +524,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
else if (bpc < 1 || bpc == 3 || (bpc > 4 && bpc < 8) || (bpc > 8 && bpc < 16) || bpc > 16)
|
else if (bpc < 1 || bpc == 3 || (bpc > 4 && bpc < 8) || (bpc > 8 && bpc < 16) || bpc > 16)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unsupported BitsPerColor value %d.", bpc);
|
_pdfioFileError(st->pdf, "Unsupported BitsPerColor value %d.", bpc);
|
||||||
free(st);
|
goto error;
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colors == 0)
|
if (colors == 0)
|
||||||
@ -540,8 +534,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
else if (colors < 0 || colors > 4)
|
else if (colors < 0 || colors > 4)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unsupported Colors value %d.", colors);
|
_pdfioFileError(st->pdf, "Unsupported Colors value %d.", colors);
|
||||||
free(st);
|
goto error;
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (columns == 0)
|
if (columns == 0)
|
||||||
@ -551,15 +544,13 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
else if (columns < 0)
|
else if (columns < 0)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unsupported Columns value %d.", columns);
|
_pdfioFileError(st->pdf, "Unsupported Columns value %d.", columns);
|
||||||
free(st);
|
goto error;
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((predictor > 2 && predictor < 10) || predictor > 15)
|
if ((predictor > 2 && predictor < 10) || predictor > 15)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unsupported Predictor function %d.", predictor);
|
_pdfioFileError(st->pdf, "Unsupported Predictor function %d.", predictor);
|
||||||
free(st);
|
goto error;
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
else if (predictor > 1)
|
else if (predictor > 1)
|
||||||
{
|
{
|
||||||
@ -573,23 +564,19 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
if ((st->prbuffer = calloc(1, st->pbsize - 1)) == NULL || (st->psbuffer = calloc(1, st->pbsize)) == NULL)
|
if ((st->prbuffer = calloc(1, st->pbsize - 1)) == NULL || (st->psbuffer = calloc(1, st->pbsize)) == NULL)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Predictor buffers.", (unsigned long)st->pbsize);
|
_pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Predictor buffers.", (unsigned long)st->pbsize);
|
||||||
free(st->prbuffer);
|
goto error;
|
||||||
free(st->psbuffer);
|
|
||||||
free(st);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
st->predictor = _PDFIO_PREDICTOR_NONE;
|
st->predictor = _PDFIO_PREDICTOR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
st->cbsize = 4096;
|
st->cbsize = 4096;
|
||||||
if ((st->cbuffer = malloc(st->cbsize)) == NULL)
|
if ((st->cbuffer = malloc(st->cbsize)) == NULL)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Flate compression buffer.", (unsigned long)st->cbsize);
|
_pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Flate compression buffer.", (unsigned long)st->cbsize);
|
||||||
free(st->prbuffer);
|
goto error;
|
||||||
free(st->psbuffer);
|
|
||||||
free(st);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFIO_DEBUG("_pdfioStreamOpen: pos=%ld\n", (long)_pdfioFileTell(st->pdf));
|
PDFIO_DEBUG("_pdfioStreamOpen: pos=%ld\n", (long)_pdfioFileTell(st->pdf));
|
||||||
@ -601,10 +588,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
if (rbytes <= 0)
|
if (rbytes <= 0)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unable to read bytes for stream.");
|
_pdfioFileError(st->pdf, "Unable to read bytes for stream.");
|
||||||
free(st->prbuffer);
|
goto error;
|
||||||
free(st->psbuffer);
|
|
||||||
free(st);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st->crypto_cb)
|
if (st->crypto_cb)
|
||||||
@ -618,10 +602,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
if ((status = inflateInit(&(st->flate))) != Z_OK)
|
if ((status = inflateInit(&(st->flate))) != Z_OK)
|
||||||
{
|
{
|
||||||
_pdfioFileError(st->pdf, "Unable to start Flate filter: %s", zstrerror(status));
|
_pdfioFileError(st->pdf, "Unable to start Flate filter: %s", zstrerror(status));
|
||||||
free(st->prbuffer);
|
goto error;
|
||||||
free(st->psbuffer);
|
|
||||||
free(st);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
st->remaining -= st->flate.avail_in;
|
st->remaining -= st->flate.avail_in;
|
||||||
@ -635,8 +616,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
{
|
{
|
||||||
// Something else we don't support
|
// Something else we don't support
|
||||||
_pdfioFileError(st->pdf, "Unsupported stream filter '/%s'.", filter);
|
_pdfioFileError(st->pdf, "Unsupported stream filter '/%s'.", filter);
|
||||||
free(st);
|
goto error;
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -646,6 +626,16 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (st);
|
return (st);
|
||||||
|
|
||||||
|
// If we get here something went wrong...
|
||||||
|
error:
|
||||||
|
|
||||||
|
free(st->cbuffer);
|
||||||
|
free(st->prbuffer);
|
||||||
|
free(st->psbuffer);
|
||||||
|
free(st);
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user