Parcourir la source

Android: Fix undefined behavior in AAsset Physfs backend when duplicating handle.

Cherry-picked from 9eacd48.
Miku AuahDark il y a 1 an
Parent
commit
d8e7441fc2
1 fichiers modifiés avec 8 ajouts et 6 suppressions
  1. 8 6
      src/common/android.cpp

+ 8 - 6
src/common/android.cpp

@@ -450,18 +450,20 @@ struct AssetInfo: public love::filesystem::physfs::PhysfsIo<AssetInfo>
 		return 1;
 	}
 
-	AssetInfo *duplicate() const
+	AssetInfo(const AssetInfo &other)
+	: assetManager(other.assetManager)
+	, size(strlen(other.filename) + 1)
 	{
-		AAsset *newAsset = AAssetManager_open(assetManager, filename, AASSET_MODE_RANDOM);
+		asset = AAssetManager_open(assetManager, other.filename, AASSET_MODE_RANDOM);
 
-		if (newAsset == nullptr)
+		if (asset == nullptr)
 		{
 			PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
-			return nullptr;
+			throw new love::Exception("Unable to duplicate AssetInfo");
 		}
 
-		AAsset_seek64(asset, tell(), SEEK_SET);
-		return fromAAsset(assetManager, filename, asset);
+		filename = new (std::nothrow) char[size];
+		memcpy(filename, other.filename, size);
 	}
 
 	~AssetInfo() override