@@ -208,8 +208,17 @@ internal class CborParser(private val input: ByteArrayInput, private val verifyO
208208 skipByte(unboundedHeader)
209209 return - 1
210210 }
211- if ((curByte and 0b111_00000 ) != boundedHeaderMask)
211+ if ((curByte and 0b111_00000 ) != boundedHeaderMask) {
212+ if (boundedHeaderMask == HEADER_ARRAY && (curByte and 0b111_00000 ) == HEADER_BYTE_STRING ) {
213+ throw CborDecodingException (
214+ " Expected a start of array, " +
215+ " but found ${printByte(curByte)} , which corresponds to the start of a byte string. " +
216+ " Make sure you correctly set 'alwaysUseByteString' setting " +
217+ " and/or 'kotlinx.serialization.cbor.ByteString' annotation."
218+ )
219+ }
212220 throw CborDecodingException (" start of $collectionType " , curByte)
221+ }
213222 val size = readNumber().toInt()
214223 readByte()
215224 return size
@@ -221,8 +230,17 @@ internal class CborParser(private val input: ByteArrayInput, private val verifyO
221230
222231 fun nextByteString (tags : ULongArray? = null): ByteArray {
223232 processTags(tags)
224- if ((curByte and 0b111_00000 ) != HEADER_BYTE_STRING )
233+ if ((curByte and 0b111_00000 ) != HEADER_BYTE_STRING ) {
234+ if (curByte and 0b111_00000 == HEADER_ARRAY ) {
235+ throw CborDecodingException (
236+ " Expected a start of a byte string, " +
237+ " but found ${printByte(curByte)} , which corresponds to the start of an array. " +
238+ " Make sure you correctly set 'alwaysUseByteString' setting " +
239+ " and/or 'kotlinx.serialization.cbor.ByteString' annotation."
240+ )
241+ }
225242 throw CborDecodingException (" start of byte string" , curByte)
243+ }
226244 val arr = readBytes()
227245 readByte()
228246 return arr
0 commit comments