Skip to content

Commit

Permalink
PAINTROID-760 Crash: Buffer underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
khalid-nasralla committed Jan 5, 2025
1 parent 6b433fd commit 9148d27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Paintroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
implementation 'androidx.exifinterface:exifinterface:1.3.2'
implementation 'com.esotericsoftware:kryo:5.5.0'
implementation 'com.esotericsoftware:kryo:5.6.2'
implementation 'id.zelory:compressor:2.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.KryoBufferUnderflowException
import com.esotericsoftware.kryo.io.Output
import org.catrobat.paintroid.colorpicker.ColorHistory
import org.catrobat.paintroid.command.Command
Expand Down Expand Up @@ -229,24 +231,26 @@ open class CommandSerializer(private val activityContext: Context, private val c
fun readFromInternalMemory(stream: FileInputStream): WorkspaceReturnValue {
var commandModel: CommandManagerModel? = null
var colorHistory: ColorHistory? = null

Input(stream).use { input ->
if (!input.readString().equals(MAGIC_VALUE)) {
throw NotCatrobatImageException("Magic Value doesn't exist.")
}
val imageVersion = input.readInt()
if (CURRENT_IMAGE_VERSION != imageVersion) {
setRegisterMapVersion(imageVersion)
registerClasses()
}
commandModel = kryo.readObject(input, CommandManagerModel::class.java)
if (input.available() != 0) {
colorHistory = kryo.readObject(input, ColorHistory::class.java)
try {
Input(stream).use { input ->
if (!input.readString().equals(MAGIC_VALUE)) {
throw NotCatrobatImageException("Magic Value doesn't exist.")
}
val imageVersion = input.readInt()
if (CURRENT_IMAGE_VERSION != imageVersion) {
setRegisterMapVersion(imageVersion)
registerClasses()
}
commandModel = kryo.readObject(input, CommandManagerModel::class.java)
if (input.available() != 0) {
colorHistory = kryo.readObject(input, ColorHistory::class.java)
}
}
commandModel?.commands?.reverse()
} catch (e: KryoBufferUnderflowException) {
Log.e("readFromInternalMemory", "Buffer underflow: ${e.message}", e)
return WorkspaceReturnValue(null, null)
}

commandModel?.commands?.reverse()

return WorkspaceReturnValue(commandModel, colorHistory)
}

Expand Down

0 comments on commit 9148d27

Please sign in to comment.