Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,7 @@ def validate_qtables(qtables):
)
i += 1

comment = info.get("comment", im.info.get("comment")) or b""
if isinstance(comment, str):
comment = comment.encode()
comment = info.get("comment", im.info.get("comment"))

# "progressive" is the official name, but older documentation
# says "progression"
Expand Down
2 changes: 1 addition & 1 deletion src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {

if (!PyArg_ParseTuple(
args,
"ss|nnnnnnnnOy#y#y#",
"ss|nnnnnnnnOz#y#y#",
&mode,
&rawmode,
&quality,
Expand Down
2 changes: 1 addition & 1 deletion src/libImaging/JpegEncode.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {

case 4:

if (context->comment_size > 0) {
if (context->comment) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest of the code is conditional on comment != NULL rather than comment_size > 0

they should be the same, but keeping things consistent feels nicer to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say "the rest of the code", what are you referring to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, that wasn't explained well

PyImaging_JpegEncoderNew seems to imply that comment_size is only valid when comment is non-NULL. e.g. comment is initialised to NULL, but comment_size isn't initialised to zero, and later in function (line 1109) it only sets comment = NULL

jpeg_write_marker(&context->cinfo, JPEG_COM, (unsigned char *)context->comment, context->comment_size);
}
state->state++;
Expand Down