Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Unified Diff: ui/gfx/codec/png_codec.cc

Issue 2576823002: Fix stack-use-after-scope in png_codec. (Closed)
Patch Set: Add comma Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/codec/png_codec.cc
diff --git a/ui/gfx/codec/png_codec.cc b/ui/gfx/codec/png_codec.cc
index ac386ad91d0b656e146776c8077694c881719e99..0fec249432d8d89fb953734033c601759458c1b7 100644
--- a/ui/gfx/codec/png_codec.cc
+++ b/ui/gfx/codec/png_codec.cc
@@ -712,8 +712,11 @@ bool EncodeWithCompressionLevel(const unsigned char* input,
NULL, NULL, NULL);
if (!png_ptr)
return false;
+ // info_ptr should have wider lifetime scope than destroyer that access it,
+ // to avoid use-after-scope bugs.
+ png_info* info_ptr;
PngWriteStructDestroyer destroyer(&png_ptr);
dcheng 2016/12/14 22:32:47 Can we move this line down to after return false?
krasin1 2016/12/14 23:45:04 Daniel, Nico, I have made a simplification that c
- png_info* info_ptr = png_create_info_struct(png_ptr);
+ info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
return false;
destroyer.SetInfoStruct(&info_ptr);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698