Skip to content

Commit 07d9e84

Browse files
committed
UserAttributeSubpacketInputStream: Adopt dynamic read limits from SignatureSubpacketInputStream
1 parent 196569e commit 07d9e84

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacketInputStream.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ public class UserAttributeSubpacketInputStream
1313
extends InputStream
1414
implements UserAttributeSubpacketTags
1515
{
16-
public static int MAX_LEN = 1 << 30;
17-
1816
InputStream in;
17+
private final int limit;
1918

2019
public UserAttributeSubpacketInputStream(
2120
InputStream in)
2221
{
22+
this(in, StreamUtil.findLimit(in));
23+
}
24+
25+
public UserAttributeSubpacketInputStream(
26+
InputStream in,
27+
int limit
28+
) {
2329
this.in = in;
30+
this.limit = limit;
2431
}
2532

2633
public int available()
@@ -77,9 +84,9 @@ public UserAttributeSubpacket readPacket()
7784
if (bodyLen < 1) {
7885
throw new MalformedPacketException("Body length octet too small.");
7986
}
80-
if (bodyLen > MAX_LEN)
87+
if (bodyLen > limit)
8188
{
82-
throw new MalformedPacketException("Body length octet (" + bodyLen + ") exceeds limitations (" + MAX_LEN + ").");
89+
throw new MalformedPacketException("Body length octet (" + bodyLen + ") exceeds limitations (" + limit + ").");
8390
}
8491
if (flags[StreamUtil.flag_eof])
8592
{

0 commit comments

Comments
 (0)