Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUACAMOLE-1875: Check return values of WebP API functions. #463

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
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
16 changes: 11 additions & 5 deletions src/libguac/encode-webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,22 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream,
config.method = 2; /* Compression method (0=fast/larger, 6=slow/smaller) */

/* Validate configuration */
WebPValidateConfig(&config);
if (!WebPValidateConfig(&config)) {
return -1;
}

/* Set up WebP picture */
WebPPictureInit(&picture);
if (!WebPPictureInit(&picture)) {
return -1;
}
picture.use_argb = 1;
picture.width = width;
picture.height = height;

/* Allocate and init writer */
WebPPictureAlloc(&picture);
if (!WebPPictureAlloc(&picture)) {
return -1;
}
picture.writer = guac_webp_stream_write;
picture.custom_ptr = &writer;
guac_webp_stream_writer_init(&writer, socket, stream);
Expand Down Expand Up @@ -244,15 +250,15 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream,
}

/* Encode image */
WebPEncode(&config, &picture);
const int result = WebPEncode(&config, &picture) ? 0 : -1;

/* Free picture */
WebPPictureFree(&picture);

/* Ensure all data is written */
guac_webp_flush_data(&writer);

return 0;
return result;

}