mirror of
https://github.com/corda/corda.git
synced 2025-04-26 13:59:56 +00:00
Add missing validation in the OpaqueBytesSubSequence.init (#4047)
This commit is contained in:
parent
d1adb09ca9
commit
5d84640d1f
@ -29,7 +29,7 @@ sealed class ByteSequence(private val _bytes: ByteArray, val offset: Int, val si
|
|||||||
*/
|
*/
|
||||||
abstract val bytes: ByteArray
|
abstract val bytes: ByteArray
|
||||||
|
|
||||||
/** Returns a [ByteArrayInputStream] of the bytes */
|
/** Returns a [ByteArrayInputStream] of the bytes. */
|
||||||
fun open() = ByteArrayInputStream(_bytes, offset, size)
|
fun open() = ByteArrayInputStream(_bytes, offset, size)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,8 +41,6 @@ sealed class ByteSequence(private val _bytes: ByteArray, val offset: Int, val si
|
|||||||
*/
|
*/
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
fun subSequence(offset: Int, size: Int): ByteSequence {
|
fun subSequence(offset: Int, size: Int): ByteSequence {
|
||||||
require(offset >= 0)
|
|
||||||
require(offset + size <= this.size)
|
|
||||||
// Intentionally use bytes rather than _bytes, to mirror the copy-or-not behaviour of that property.
|
// Intentionally use bytes rather than _bytes, to mirror the copy-or-not behaviour of that property.
|
||||||
return if (offset == 0 && size == this.size) this else of(bytes, this.offset + offset, size)
|
return if (offset == 0 && size == this.size) this else of(bytes, this.offset + offset, size)
|
||||||
}
|
}
|
||||||
@ -108,7 +106,7 @@ sealed class ByteSequence(private val _bytes: ByteArray, val offset: Int, val si
|
|||||||
return Integer.signum(unsignedThis - unsignedOther)
|
return Integer.signum(unsignedThis - unsignedOther)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// First min bytes is the same, so now resort to size
|
// First min bytes is the same, so now resort to size.
|
||||||
return Integer.signum(this.size - other.size)
|
return Integer.signum(this.size - other.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,12 +188,12 @@ fun ByteArray.toHexString(): String = DatatypeConverter.printHexBinary(this)
|
|||||||
fun String.parseAsHex(): ByteArray = DatatypeConverter.parseHexBinary(this)
|
fun String.parseAsHex(): ByteArray = DatatypeConverter.parseHexBinary(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class is public for serialization purposes
|
* Class is public for serialization purposes.
|
||||||
*/
|
*/
|
||||||
@KeepForDJVM
|
@KeepForDJVM
|
||||||
class OpaqueBytesSubSequence(override val bytes: ByteArray, offset: Int, size: Int) : ByteSequence(bytes, offset, size) {
|
class OpaqueBytesSubSequence(override val bytes: ByteArray, offset: Int, size: Int) : ByteSequence(bytes, offset, size) {
|
||||||
init {
|
init {
|
||||||
require(offset >= 0 && offset < bytes.size)
|
require(offset >= 0 && offset < bytes.size)
|
||||||
require(size >= 0 && size <= bytes.size)
|
require(size >= 0 && offset + size <= bytes.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user