mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Changed maximum comment length to 65531
This commit is contained in:
parent
598216fb46
commit
2f66d2d6a1
|
@ -376,14 +376,18 @@ def test_save_comment():
|
||||||
for comment in ("Created by Pillow", b"Created by Pillow"):
|
for comment in ("Created by Pillow", b"Created by Pillow"):
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
test_card.save(out, "JPEG2000", comment=comment)
|
test_card.save(out, "JPEG2000", comment=comment)
|
||||||
out.seek(0)
|
|
||||||
|
|
||||||
with Image.open(out) as im:
|
with Image.open(out) as im:
|
||||||
assert im.info["comment"] == b"Created by Pillow"
|
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):
|
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(
|
@pytest.mark.parametrize(
|
||||||
|
|
|
@ -1214,7 +1214,7 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
|
||||||
char mct = 0;
|
char mct = 0;
|
||||||
int sgnd = 0;
|
int sgnd = 0;
|
||||||
Py_ssize_t fd = -1;
|
Py_ssize_t fd = -1;
|
||||||
char *comment = NULL;
|
char *comment;
|
||||||
Py_ssize_t comment_size;
|
Py_ssize_t comment_size;
|
||||||
int plt = 0;
|
int plt = 0;
|
||||||
|
|
||||||
|
@ -1323,7 +1323,7 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
if (comment && comment_size > 0) {
|
if (comment && comment_size > 0) {
|
||||||
/* Size is stored as as an uint16, subtract 4 bytes for the header */
|
/* Size is stored as as an uint16, subtract 4 bytes for the header */
|
||||||
if (comment_size >= 65531) {
|
if (comment_size >= 65532) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_ValueError,
|
PyExc_ValueError,
|
||||||
"JPEG 2000 comment is too long");
|
"JPEG 2000 comment is too long");
|
||||||
|
|
|
@ -503,7 +503,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state) {
|
||||||
/* Enabling PLT markers only supported in OpenJPEG 2.4.0 and up */
|
/* 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 ((OPJ_VERSION_MAJOR == 2 && OPJ_VERSION_MINOR >= 4) || OPJ_VERSION_MAJOR > 2)
|
||||||
if (context->plt) {
|
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);
|
opj_encoder_set_extra_options(codec, plt_option);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user