Skip to content

Commit

Permalink
Fix #2903: Avoid systematic checking of String integrity in IEEE754He…
Browse files Browse the repository at this point in the history
…lpers (#2907)
  • Loading branch information
david-bouyssie committed Oct 21, 2022
1 parent c739841 commit 8d491c5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions javalib/src/main/scala/java/lang/IEEE754Helpers.scala
Expand Up @@ -74,16 +74,21 @@ private[java] object IEEE754Helpers {

val nSeen = !end - cStr

// magic: is first char one of D d F f
var idx =
if ((cStr(nSeen.toUSize) & 0xdd) == 0x44) (nSeen + 1) else nSeen

while (idx < bytesLen) { // Check for garbage in the unparsed remnant.
val b = cStr(idx.toUSize)
if ((b < 0) || b > 0x20) {
throw new NumberFormatException(exceptionMsg(s))
// If we used less bytes than in our input, there is a risk that the input contains invalid characters.
// We should thus verify if the input contains only valid characters.
// See: https://github.com/scala-native/scala-native/issues/2903
if (nSeen != bytesLen) {
// magic: is first char one of D d F f
var idx =
if ((cStr(nSeen.toUSize) & 0xdd) == 0x44) (nSeen + 1) else nSeen

while (idx < bytesLen) { // Check for garbage in the unparsed remnant.
val b = cStr(idx.toUSize)
if ((b < 0) || b > 0x20) {
throw new NumberFormatException(exceptionMsg(s))
}
idx += 1
}
idx += 1
}
}

Expand Down

0 comments on commit 8d491c5

Please sign in to comment.