Skip to content

Commit 085a7f1

Browse files
TimPushkinAlexey Bakhtin
authored andcommitted
8347911: Limit the length of inflated text chunks
Backport-of: 398a580518b4e7961bdddf733e0a89ff25bc437a
1 parent c5f39c9 commit 085a7f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -139,6 +139,7 @@ public class PNGImageReader extends ImageReader {
139139
static final int tRNS_TYPE = 0x74524e53;
140140
static final int zTXt_TYPE = 0x7a545874;
141141

142+
static final int MAX_INFLATED_TEXT_LENGTH = 262144;
142143
static final int PNG_COLOR_GRAY = 0;
143144
static final int PNG_COLOR_RGB = 2;
144145
static final int PNG_COLOR_PALETTE = 3;
@@ -661,7 +662,7 @@ private void parse_tRNS_chunk(int chunkLength) throws IOException {
661662
private static byte[] inflate(byte[] b) throws IOException {
662663
InputStream bais = new ByteArrayInputStream(b);
663664
try (InputStream iis = new InflaterInputStream(bais)) {
664-
return iis.readAllBytes();
665+
return iis.readNBytes(MAX_INFLATED_TEXT_LENGTH);
665666
}
666667
}
667668

0 commit comments

Comments
 (0)