diff --git a/src/java.base/share/classes/sun/security/util/DerIndefLenConverter.java b/src/java.base/share/classes/sun/security/util/DerIndefLenConverter.java index a0e802b9580..f429ec41ef0 100644 --- a/src/java.base/share/classes/sun/security/util/DerIndefLenConverter.java +++ b/src/java.base/share/classes/sun/security/util/DerIndefLenConverter.java @@ -144,15 +144,14 @@ class DerIndefLenConverter { * then skip the tag and its 1 byte length of zero. */ private void writeTag() { - if (dataPos == dataSize) { - return; - } - assert dataPos + 1 < dataSize; - if (isEOC(data, dataPos)) { - dataPos += 2; // skip tag and length - writeTag(); - } else { - newData[newDataPos++] = data[dataPos++]; + while (dataPos < dataSize) { + assert dataPos + 1 < dataSize; + if (isEOC(data, dataPos)) { + dataPos += 2; // skip tag and length + } else { + newData[newDataPos++] = data[dataPos++]; + break; + } } }