Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAINTROID-760 Crash: Buffer underflow #1344

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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