diff options
author | Dana Dahlstrom <dahlstrom@google.com> | 2020-02-12 11:00:00 -0800 |
---|---|---|
committer | Dana Dahlstrom <dahlstrom@google.com> | 2020-02-12 11:00:00 -0800 |
commit | 86a106a12234cee1498a2159104fcba7f3c0efed (patch) | |
tree | d87095c67859d1df4f0b8b34b4744aa68bcccce2 /src/share/classes/java/awt/color/ICC_Profile.java | |
parent | 48adcc45b3935045b1ff2013ecfd05e6f3bdb1cc (diff) | |
parent | a7492bb2a38c1c41216929de6ba6a0a553bd4338 (diff) | |
download | jdk8u_jdk-86a106a12234cee1498a2159104fcba7f3c0efed.tar.gz |
Merge tag jb8u242-b1644.3
Change-Id: Ia7492bb2a38c1c41216929de6ba6a0a553bd4338
Diffstat (limited to 'src/share/classes/java/awt/color/ICC_Profile.java')
-rw-r--r-- | src/share/classes/java/awt/color/ICC_Profile.java | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/src/share/classes/java/awt/color/ICC_Profile.java b/src/share/classes/java/awt/color/ICC_Profile.java index 89abeca03d..af1e5fc700 100644 --- a/src/share/classes/java/awt/color/ICC_Profile.java +++ b/src/share/classes/java/awt/color/ICC_Profile.java @@ -43,7 +43,9 @@ import sun.java2d.cmm.ProfileDataVerifier; import sun.java2d.cmm.ProfileDeferralMgr; import sun.java2d.cmm.ProfileDeferralInfo; import sun.java2d.cmm.ProfileActivator; +import sun.misc.IOUtils; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -1019,42 +1021,25 @@ public class ICC_Profile implements Serializable { static byte[] getProfileDataFromStream(InputStream s) throws IOException { - byte profileData[]; - int profileSize; - byte header[] = new byte[128]; - int bytestoread = 128; - int bytesread = 0; - int n; + BufferedInputStream bis = new BufferedInputStream(s); + bis.mark(128); - while (bytestoread != 0) { - if ((n = s.read(header, bytesread, bytestoread)) < 0) { - return null; - } - bytesread += n; - bytestoread -= n; - } + byte[] header = IOUtils.readNBytes(bis, 128); if (header[36] != 0x61 || header[37] != 0x63 || header[38] != 0x73 || header[39] != 0x70) { return null; /* not a valid profile */ } - profileSize = ((header[0] & 0xff) << 24) | - ((header[1] & 0xff) << 16) | - ((header[2] & 0xff) << 8) | - (header[3] & 0xff); - profileData = new byte[profileSize]; - System.arraycopy(header, 0, profileData, 0, 128); - bytestoread = profileSize - 128; - bytesread = 128; - while (bytestoread != 0) { - if ((n = s.read(profileData, bytesread, bytestoread)) < 0) { - return null; - } - bytesread += n; - bytestoread -= n; + int profileSize = ((header[0] & 0xff) << 24) | + ((header[1] & 0xff) << 16) | + ((header[2] & 0xff) << 8) | + (header[3] & 0xff); + bis.reset(); + try { + return IOUtils.readNBytes(bis, profileSize); + } catch (OutOfMemoryError e) { + throw new IOException("Color profile is too big"); } - - return profileData; } |