Changed maximum comment length to 65531

This commit is contained in:
Andrew Murray 2023-03-29 19:19:05 +11:00
parent 598216fb46
commit 2f66d2d6a1
3 changed files with 10 additions and 6 deletions

View File

@ -376,14 +376,18 @@ def test_save_comment():
for comment in ("Created by Pillow", b"Created by Pillow"):
out = BytesIO()
test_card.save(out, "JPEG2000", comment=comment)
out.seek(0)
with Image.open(out) as im:
assert im.info["comment"] == b"Created by Pillow"
too_long_comment = " " * 65531
out = BytesIO()
long_comment = b" " * 65531
test_card.save(out, "JPEG2000", comment=long_comment)
with Image.open(out) as im:
assert im.info["comment"] == long_comment
with pytest.raises(ValueError):
test_card.save(out, "JPEG2000", comment=too_long_comment)
test_card.save(out, "JPEG2000", comment=long_comment + b" ")
@pytest.mark.parametrize(

View File

@ -1214,7 +1214,7 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
char mct = 0;
int sgnd = 0;
Py_ssize_t fd = -1;
char *comment = NULL;
char *comment;
Py_ssize_t comment_size;
int plt = 0;
@ -1323,7 +1323,7 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
if (comment && comment_size > 0) {
/* Size is stored as as an uint16, subtract 4 bytes for the header */
if (comment_size >= 65531) {
if (comment_size >= 65532) {
PyErr_SetString(
PyExc_ValueError,
"JPEG 2000 comment is too long");

View File

@ -503,7 +503,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state) {
/* Enabling PLT markers only supported in OpenJPEG 2.4.0 and up */
#if ((OPJ_VERSION_MAJOR == 2 && OPJ_VERSION_MINOR >= 4) || OPJ_VERSION_MAJOR > 2)
if (context->plt) {
const char * plt_option[2] = {"PLT=YES", NULL};
const char *plt_option[2] = {"PLT=YES", NULL};
opj_encoder_set_extra_options(codec, plt_option);
}
#endif