mirror of
https://github.com/fluencelabs/asmble
synced 2025-07-03 08:21:36 +00:00
Updated wasm spec and enforced UTF-8 validation on binary strings
This commit is contained in:
@ -2,6 +2,7 @@ package asmble.io
|
||||
|
||||
import asmble.ast.Node
|
||||
import asmble.util.*
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
open class BinaryToAst(
|
||||
val version: Long = 1L,
|
||||
@ -215,7 +216,10 @@ open class BinaryToAst(
|
||||
else -> error("Unknown value type: $type")
|
||||
}
|
||||
|
||||
fun ByteReader.readString() = this.readVarUInt32AsInt().let { String(this.readBytes(it)) }
|
||||
fun ByteReader.readString() = this.readVarUInt32AsInt().let {
|
||||
// We have to use the decoder directly to get malformed-input errors
|
||||
Charsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(this.readBytes(it))).toString()
|
||||
}
|
||||
fun <T> ByteReader.readList(fn: (ByteReader) -> T) = this.readVarUInt32().let { listSize ->
|
||||
(0 until listSize).map { fn(this) }
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import asmble.AsmErr
|
||||
sealed class IoErr(message: String, cause: Throwable? = null) : RuntimeException(message, cause), AsmErr {
|
||||
class UnexpectedEnd : IoErr("Unexpected EOF") {
|
||||
override val asmErrString get() = "unexpected end"
|
||||
override val asmErrStrings get() = listOf(asmErrString, "length out of bounds")
|
||||
}
|
||||
|
||||
class InvalidMagicNumber : IoErr("Invalid magic number") {
|
||||
|
@ -3,6 +3,7 @@ package asmble.run.jvm
|
||||
import asmble.AsmErr
|
||||
import java.lang.invoke.WrongMethodTypeException
|
||||
import java.nio.BufferOverflowException
|
||||
import java.nio.charset.MalformedInputException
|
||||
|
||||
open class ExceptionTranslator {
|
||||
fun translate(ex: Throwable): List<String> = when (ex) {
|
||||
@ -13,6 +14,7 @@ open class ExceptionTranslator {
|
||||
is ArrayIndexOutOfBoundsException -> listOf("undefined element", "elements segment does not fit")
|
||||
is AsmErr -> ex.asmErrStrings
|
||||
is IndexOutOfBoundsException -> listOf("out of bounds memory access")
|
||||
is MalformedInputException -> listOf("invalid UTF-8 encoding")
|
||||
is NoSuchMethodException -> listOf("unknown import", "type mismatch")
|
||||
is NullPointerException -> listOf("undefined element", "uninitialized element")
|
||||
is StackOverflowError -> listOf("call stack exhausted")
|
||||
|
Submodule compiler/src/test/resources/spec updated: 671b08d0e7...913fbf477e
Reference in New Issue
Block a user