Merge pull request from GHSA-v2h9-jfmf-5cgq

GHSL-2023-092: Check if i is not bigger than datalen
pull/14079/head
Don HO 2023-08-31 14:30:53 +02:00 committed by GitHub
commit 5402622abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -1390,8 +1390,11 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
break;
}
if (i == dataLen)
return L_TEXT;
// Create the buffer to need to test
const size_t longestLength = 40; // shebangs can be large
const size_t longestLength = std::min<size_t>(40, dataLen - i); // shebangs can be large
std::string buf2Test = std::string((const char *)data + i, longestLength);
// Is there a \r or \n in the buffer? If so, truncate it