Browse Source

Fixed bug with paths containing .. and .

Tim Newell 12 years ago
parent
commit
434cf1dce6
1 changed files with 26 additions and 3 deletions
  1. 26 3
      engine/source/platformAndroid/T2DActivity.cpp

+ 26 - 3
engine/source/platformAndroid/T2DActivity.cpp

@@ -509,13 +509,36 @@ bool _AndroidGetFileDescriptor(const char* fileName, int32_t *mDescriptor, off_t
 char* _AndroidLoadFile(const char* fn, U32 *size) {
 char* _AndroidLoadFile(const char* fn, U32 *size) {
 
 
 	char fileName[255];
 	char fileName[255];
-	if (fn[0] == '/')
+
+	//Check for .. in path and remove them so apk reading code doesnt choke on it
+	std::string filepath = fn;
+	//first remove any cases of /./
+	std::string find = "/./";
+	size_t start_pos = filepath.find(find);
+	while (start_pos != std::string::npos)
+	{
+		filepath.replace(start_pos+1, find.length()-1, "");
+		start_pos = filepath.find(find);
+	}
+
+	find = "/../";
+	start_pos = filepath.find(find);
+	while (start_pos != std::string::npos)
+	{
+		size_t begin_pos = filepath.rfind("/", start_pos-1);
+		filepath.replace(begin_pos, (start_pos - begin_pos - 1) + find.length(), "");
+		start_pos = filepath.find(find);
+
+	}
+	if (filepath.find("/") == 0)
 	{
 	{
-		strcpy(fileName, fn+1);
+		strcpy(fileName, filepath.substr(1).c_str());
+		fileName[filepath.size()-1] = '\0';
 	}
 	}
 	else
 	else
 	{
 	{
-		strcpy(fileName,fn);
+		strcpy(fileName, filepath.c_str());
+		fileName[filepath.size()] = '\0';
 	}
 	}
 
 
 	AAsset *asset;
 	AAsset *asset;