Added input stream property checks.

This commit is contained in:
jakcron 2021-10-03 12:01:23 +08:00
parent 5670cb7e16
commit ece2906cde
6 changed files with 29 additions and 5 deletions

View file

@ -60,6 +60,10 @@ void nstool::AssetProcess::importHeader()
{
throw tc::Exception(mModuleName, "No file reader set.");
}
if (mFile->canRead() == false || mFile->canSeek() == false)
{
throw tc::NotSupportedException(mModuleName, "Input stream requires read/seek permissions.");
}
if (mFile->length() < tc::io::IOUtil::castSizeToInt64(sizeof(nn::hac::sAssetHeader)))
{

View file

@ -44,6 +44,10 @@ void nstool::CnmtProcess::importCnmt()
{
throw tc::Exception(mModuleName, "No file reader set.");
}
if (mFile->canRead() == false || mFile->canSeek() == false)
{
throw tc::NotSupportedException(mModuleName, "Input stream requires read/seek permissions.");
}
// check if file_size is greater than 20MB, don't import.
size_t cnmt_file_size = tc::io::IOUtil::castInt64ToSize(mFile->length());

View file

@ -53,6 +53,10 @@ void nstool::EsTikProcess::importTicket()
{
throw tc::Exception(mModuleName, "No file reader set.");
}
if (mFile->canRead() == false || mFile->canSeek() == false)
{
throw tc::NotSupportedException(mModuleName, "Input stream requires read/seek permissions.");
}
// check if file_size is greater than 20MB, don't import.
size_t file_size = tc::io::IOUtil::castInt64ToSize(mFile->length());

View file

@ -44,12 +44,16 @@ void nstool::NacpProcess::importNacp()
{
throw tc::Exception(mModuleName, "No file reader set.");
}
// check if file_size is greater than 20MB, don't import.
size_t file_size = tc::io::IOUtil::castInt64ToSize(mFile->length());
if (file_size > (0x100000 * 20))
if (mFile->canRead() == false || mFile->canSeek() == false)
{
throw tc::Exception(mModuleName, "File too large.");
throw tc::NotSupportedException(mModuleName, "Input stream requires read/seek permissions.");
}
// check if file_size does matches expected size
size_t file_size = tc::io::IOUtil::castInt64ToSize(mFile->length());
if (file_size != sizeof(nn::hac::sApplicationControlProperty))
{
throw tc::Exception(mModuleName, "File was incorrect size.");
}
// read cnmt

View file

@ -78,6 +78,10 @@ void nstool::PfsProcess::importHeader()
{
throw tc::Exception(mModuleName, "No file reader set.");
}
if (mFile->canRead() == false || mFile->canSeek() == false)
{
throw tc::NotSupportedException(mModuleName, "Input stream requires read/seek permissions.");
}
tc::ByteData scratch;

View file

@ -71,6 +71,10 @@ void nstool::RomfsProcess::importHeader()
{
throw tc::Exception(mModuleName, "No file reader set.");
}
if (mFile->canRead() == false || mFile->canSeek() == false)
{
throw tc::NotSupportedException(mModuleName, "Input stream requires read/seek permissions.");
}
tc::ByteData scratch;