History

fix parseonly length overflow

huili2 committed 9 years ago

Commit 17139511 parent 2ca99128 files · +370 −24Browse files

Showing the changes to test/decoder/DecUT_ParseSyntax.cpp (1 of 8 files). Show all

Unified · Split

test/decoder/DecUT_ParseSyntax.cpp+77−4
@@ -58,7 +58,7 @@ DECODING_STATE DecodeFrame (const unsigned char* kpSrc, · 57 unmodified lines
58 return dsErrorFree;58 return dsErrorFree;
59}59}
60 60
61void UninitDecoder (PWelsDecoderContext pCtx) {61void UninitDecoder (PWelsDecoderContext& pCtx) {
62 if (NULL == pCtx)62 if (NULL == pCtx)
63 return;63 return;
64 64
@@ -132,11 +132,13 @@ class DecoderParseSyntaxTest : public ::testing::Test { · 67 unmodified lines
132 //Uninit members132 //Uninit members
133 void Uninit();133 void Uninit();
134 //Decoder real bitstream134 //Decoder real bitstream
135// void DecoderBs (const char* sFileName);
136 //Parse real bitstream
137 void DecodeBs (const char* sFileName);135 void DecodeBs (const char* sFileName);
136 //Parse real bitstream
137 void ParseBs (const char* sFileName);
138 //Scalinglist138 //Scalinglist
139 void TestScalingList();139 void TestScalingList();
140 //specific bitstream test
141 void TestSpecificBs();
140 //Do whole tests here142 //Do whole tests here
141 void DecoderParseSyntaxTestAll();143 void DecoderParseSyntaxTestAll();
142 144
@@ -250,6 +252,66 @@ void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 107 unmodified lines
250 252
251 253
252}254}
255void DecoderParseSyntaxTest::ParseBs (const char* sFileName) {
256
257 uint8_t* pBuf = NULL;
258 int32_t iBufPos = 0;
259 int32_t iFileSize;
260 int32_t i = 0;
261 int32_t iSliceSize;
262 int32_t iSliceIndex = 0;
263 int32_t iEndOfStreamFlag = 0;
264 FILE* pH264File;
265 uint8_t uiStartCode[4] = { 0, 0, 0, 1 };
266 int iRet;
267
268#if defined(ANDROID_NDK)
269 std::string filename = std::string ("/sdcard/") + sFileName;
270 ASSERT_TRUE ((pH264File = fopen (filename.c_str(), "rb")) != NULL);
271#else
272 ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL);
273#endif
274 fseek (pH264File, 0L, SEEK_END);
275 iFileSize = (int32_t)ftell (pH264File);
276 fseek (pH264File, 0L, SEEK_SET);
277 pBuf = new uint8_t[iFileSize + 4];
278 ASSERT_EQ (fread (pBuf, 1, iFileSize, pH264File), (unsigned int)iFileSize);
279 memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage
280 while (true) {
281 if (iBufPos >= iFileSize) {
282 iEndOfStreamFlag = true;
283 if (iEndOfStreamFlag)
284 m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, (void*)&iEndOfStreamFlag);
285 break;
286 }
287 for (i = 0; i < iFileSize; i++) {
288 if ((pBuf[iBufPos + i] == 0 && pBuf[iBufPos + i + 1] == 0 && pBuf[iBufPos + i + 2] == 0 && pBuf[iBufPos + i + 3] == 1
289 && i > 0)) {
290 break;
291 }
292 }
293 iSliceSize = i;
294 memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo));
295 iRet = m_pDec->DecodeParser (pBuf + iBufPos, iSliceSize, &m_sParserBsInfo);
296 EXPECT_TRUE (iRet == dsErrorFree || iRet == dsFramePending);
297 iRet = m_pDec->DecodeParser (NULL, 0, &m_sParserBsInfo);
298 EXPECT_TRUE (iRet == dsErrorFree || iRet == dsFramePending);
299 iBufPos += iSliceSize;
300 ++iSliceIndex;
301 if (iSliceIndex == 4)
302 break;
303 }
304
305 fclose (pH264File);
306 if (pBuf) {
307 delete[] pBuf;
308 pBuf = NULL;
309 }
310
311
312}
313
314
253void DecoderParseSyntaxTest::TestScalingList() {315void DecoderParseSyntaxTest::TestScalingList() {
254 uint8_t iScalingList[6][16] = {316 uint8_t iScalingList[6][16] = {
255 {17, 17, 16, 16, 17, 16, 15, 15, 16, 15, 15, 15, 16, 15, 15, 15 },317 {17, 17, 16, 16, 17, 16, 15, 15, 16, 15, 15, 15, 16, 15, 15, 15 },
@@ -295,11 +357,22 @@ void DecoderParseSyntaxTest::TestScalingList() { · 39 unmodified lines
295 Uninit();357 Uninit();
296}358}
297 359
360void DecoderParseSyntaxTest::TestSpecificBs() {
361 int32_t iRet = ERR_NONE;
362 Uninit();
363 m_sDecParam.bParseOnly = true;
364 m_sDecParam.eEcActiveIdc = ERROR_CON_DISABLE;
365 iRet = m_pDec->Initialize (&m_sDecParam);
366 ASSERT_EQ (iRet, ERR_NONE);
367 ParseBs ("res/jm_1080p_allslice.264");
368 m_pDec->Uninitialize();
369 //Uninit();
370}
298//TEST here for whole tests371//TEST here for whole tests
299TEST_F (DecoderParseSyntaxTest, DecoderParseSyntaxTestAll) {372TEST_F (DecoderParseSyntaxTest, DecoderParseSyntaxTestAll) {
300 373
301 TestScalingList();374 TestScalingList();
302 375 TestSpecificBs();
303}376}
304 377
305 378

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t