Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
try to make extracting epubs safer
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Jun 26, 2019
1 parent 1847f89 commit 9317589
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/zipios/src/zipextraction.cpp
Expand Up @@ -73,7 +73,17 @@ void ExtractZipToFolder( const fs::path &path_to_zip, const fs::path &path_to_fo
{
boost::scoped_ptr< std::istream > stream( zip.getInputStream( *it ) );

fs::path new_file_path = path_to_folder / (*it)->getName();
// for security reasons need to force any relative path
// to be inside the destination folder and not anyplace else
// do this by removing any and all upward relative path segments as
// epubs are not general zip archives used for backup
string azipfilepath = (*it)->getName();
size_t index = azipfilepath.find("../", 0);
while(index != std::string::npos) {
azipfilepath.replace(index, 3,"");
index = azipfilepath.find("../", 0);
}
fs::path new_file_path = path_to_folder / azipfilepath;

CreateFilepath( new_file_path );
WriteEntryToFile( *stream, new_file_path );
Expand Down

0 comments on commit 9317589

Please sign in to comment.