Skip to content

Commit 9148d27

Browse files
PAINTROID-760 Crash: Buffer underflow
1 parent 6b433fd commit 9148d27

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

Paintroid/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ dependencies {
125125
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'
126126
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
127127
implementation 'androidx.exifinterface:exifinterface:1.3.2'
128-
implementation 'com.esotericsoftware:kryo:5.5.0'
128+
implementation 'com.esotericsoftware:kryo:5.6.2'
129129
implementation 'id.zelory:compressor:2.1.1'
130130
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
131131

Paintroid/src/main/java/org/catrobat/paintroid/command/serialization/CommandSerializer.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ import android.net.Uri
3232
import android.os.Build
3333
import android.os.Environment
3434
import android.provider.MediaStore
35+
import android.util.Log
3536
import com.esotericsoftware.kryo.Kryo
3637
import com.esotericsoftware.kryo.io.Input
38+
import com.esotericsoftware.kryo.io.KryoBufferUnderflowException
3739
import com.esotericsoftware.kryo.io.Output
3840
import org.catrobat.paintroid.colorpicker.ColorHistory
3941
import org.catrobat.paintroid.command.Command
@@ -229,24 +231,26 @@ open class CommandSerializer(private val activityContext: Context, private val c
229231
fun readFromInternalMemory(stream: FileInputStream): WorkspaceReturnValue {
230232
var commandModel: CommandManagerModel? = null
231233
var colorHistory: ColorHistory? = null
232-
233-
Input(stream).use { input ->
234-
if (!input.readString().equals(MAGIC_VALUE)) {
235-
throw NotCatrobatImageException("Magic Value doesn't exist.")
236-
}
237-
val imageVersion = input.readInt()
238-
if (CURRENT_IMAGE_VERSION != imageVersion) {
239-
setRegisterMapVersion(imageVersion)
240-
registerClasses()
241-
}
242-
commandModel = kryo.readObject(input, CommandManagerModel::class.java)
243-
if (input.available() != 0) {
244-
colorHistory = kryo.readObject(input, ColorHistory::class.java)
234+
try {
235+
Input(stream).use { input ->
236+
if (!input.readString().equals(MAGIC_VALUE)) {
237+
throw NotCatrobatImageException("Magic Value doesn't exist.")
238+
}
239+
val imageVersion = input.readInt()
240+
if (CURRENT_IMAGE_VERSION != imageVersion) {
241+
setRegisterMapVersion(imageVersion)
242+
registerClasses()
243+
}
244+
commandModel = kryo.readObject(input, CommandManagerModel::class.java)
245+
if (input.available() != 0) {
246+
colorHistory = kryo.readObject(input, ColorHistory::class.java)
247+
}
245248
}
249+
commandModel?.commands?.reverse()
250+
} catch (e: KryoBufferUnderflowException) {
251+
Log.e("readFromInternalMemory", "Buffer underflow: ${e.message}", e)
252+
return WorkspaceReturnValue(null, null)
246253
}
247-
248-
commandModel?.commands?.reverse()
249-
250254
return WorkspaceReturnValue(commandModel, colorHistory)
251255
}
252256

0 commit comments

Comments
 (0)