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
5858 return dsErrorFree;
5959 }
6060
61−void UninitDecoder (PWelsDecoderContext pCtx) {
61+void UninitDecoder (PWelsDecoderContext& pCtx) {
6262 if (NULL == pCtx)
6363 return;
6464
@@ -132,11 +132,13 @@ class DecoderParseSyntaxTest : public ::testing::Test { · 67 unmodified lines
132132 //Uninit members
133133 void Uninit();
134134 //Decoder real bitstream
135−// void DecoderBs (const char* sFileName);
136− //Parse real bitstream
137135 void DecodeBs (const char* sFileName);
136+ //Parse real bitstream
137+ void ParseBs (const char* sFileName);
138138 //Scalinglist
139139 void TestScalingList();
140+ //specific bitstream test
141+ void TestSpecificBs();
140142 //Do whole tests here
141143 void DecoderParseSyntaxTestAll();
142144
@@ -250,6 +252,66 @@ void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 107 unmodified lines
250252
251253
252254 }
255+void 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+
253315 void DecoderParseSyntaxTest::TestScalingList() {
254316 uint8_t iScalingList[6][16] = {
255317 {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
295357 Uninit();
296358 }
297359
360+void 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+}
298371 //TEST here for whole tests
299372 TEST_F (DecoderParseSyntaxTest, DecoderParseSyntaxTestAll) {
300373
301374 TestScalingList();
302−
375+ TestSpecificBs();
303376 }
304377
305378

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