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

Side by Side Diff: tests/CodexTest.cpp

Issue 1058873006: Get rid of leaks in SkCodec::NewFromStream. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comment that ReadHeader does not own SkStream. Created 5 years, 8 months 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 unified diff | Download patch
« no previous file with comments | « src/codec/SkCodec_wbmp.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); 102 check(r, "mandrill_128.png", SkISize::Make(128, 128), true);
103 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); 103 check(r, "mandrill_16.png", SkISize::Make(16, 16), true);
104 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); 104 check(r, "mandrill_256.png", SkISize::Make(256, 256), true);
105 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); 105 check(r, "mandrill_32.png", SkISize::Make(32, 32), true);
106 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); 106 check(r, "mandrill_512.png", SkISize::Make(512, 512), true);
107 check(r, "mandrill_64.png", SkISize::Make(64, 64), true); 107 check(r, "mandrill_64.png", SkISize::Make(64, 64), true);
108 check(r, "plane.png", SkISize::Make(250, 126), true); 108 check(r, "plane.png", SkISize::Make(250, 126), true);
109 check(r, "randPixels.png", SkISize::Make(8, 8), true); 109 check(r, "randPixels.png", SkISize::Make(8, 8), true);
110 check(r, "yellow_rose.png", SkISize::Make(400, 301), true); 110 check(r, "yellow_rose.png", SkISize::Make(400, 301), true);
111 } 111 }
112
113 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_ t len) {
114 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals e));
115 // We should not have gotten a codec. Bots should catch us if we leaked anyt hing.
116 REPORTER_ASSERT(r, !codec);
117 }
118
119 // Ensure that SkCodec::NewFromStream handles freeing the passed in SkStream,
120 // even on failure. Test some bad streams.
121 DEF_TEST(Codec_leaks, r) {
122 // No codec should claim this as their format, so this tests SkCodec::NewFro mStream.
123 const char nonSupportedStream[] = "hello world";
124 // The other strings should look like the beginning of a file type, so we'll call some
125 // internal version of NewFromStream, which must also delete the stream on f ailure.
126 const unsigned char emptyPng[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
127 const unsigned char emptyJpeg[] = { 0xFF, 0xD8, 0xFF };
128 const char emptyWebp[] = "RIFF1234WEBPVP";
129 const char emptyBmp[] = { 'B', 'M' };
130 const char emptyIco[] = { '\x00', '\x00', '\x01', '\x00' };
131 const char emptyGif[] = "GIFVER";
132
133 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream));
134 test_invalid_stream(r, emptyPng, sizeof(emptyPng));
135 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg));
136 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp));
137 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp));
138 test_invalid_stream(r, emptyIco, sizeof(emptyIco));
139 test_invalid_stream(r, emptyGif, sizeof(emptyGif));
140 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_wbmp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698