Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb55ec5b

Browse files
committed
8271718: Crash when during color transformation the color profile is replaced
Backport-of: 148935279d177e66a08a7003975bce3077104e07
1 parent4e707bc commitb55ec5b

File tree

2 files changed

+162
-10
lines changed

2 files changed

+162
-10
lines changed

‎src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMS.java‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@
2727

2828
importjava.awt.color.CMMException;
2929
importjava.awt.color.ICC_Profile;
30+
importjava.util.concurrent.locks.StampedLock;
3031

3132
importsun.java2d.cmm.ColorTransform;
3233
importsun.java2d.cmm.PCMM;
3334
importsun.java2d.cmm.Profile;
3435

3536
finalclassLCMSimplementsPCMM {
3637

38+
/**
39+
* Prevent changing profiles data during transform creation.
40+
*/
41+
privatestaticfinalStampedLocklock =newStampedLock();
42+
3743
/* methods invoked from ICC_Profile */
3844
@Override
3945
publicProfileloadProfile(byte[]data) {
@@ -80,8 +86,13 @@ public byte[] getTagData(Profile p, int tagSignature) {
8086
}
8187

8288
@Override
83-
publicsynchronizedvoidsetTagData(Profilep,inttagSignature,byte[]data) {
84-
getLcmsProfile(p).setTag(tagSignature,data);
89+
publicvoidsetTagData(Profilep,inttagSignature,byte[]data) {
90+
longstamp =lock.writeLock();
91+
try {
92+
getLcmsProfile(p).setTag(tagSignature,data);
93+
}finally {
94+
lock.unlockWrite(stamp);
95+
}
8596
}
8697

8798
staticsynchronizednativeLCMSProfilegetProfileID(ICC_Profileprofile);
@@ -94,15 +105,20 @@ static long createTransform(
94105
ObjectdisposerRef)
95106
{
96107
long[]ptrs =newlong[profiles.length];
97-
98-
for (inti =0;i <profiles.length;i++) {
99-
if (profiles[i] ==null)thrownewCMMException("Unknown profile ID");
100-
101-
ptrs[i] =profiles[i].getLcmsPtr();
108+
longstamp =lock.readLock();
109+
try {
110+
for (inti =0;i <profiles.length;i++) {
111+
if (profiles[i] ==null) {
112+
thrownewCMMException("Unknown profile ID");
113+
}
114+
ptrs[i] =profiles[i].getLcmsPtr();
115+
}
116+
117+
returncreateNativeTransform(ptrs,renderType,inFormatter,
118+
isInIntPacked,outFormatter,isOutIntPacked,disposerRef);
119+
}finally {
120+
lock.unlockRead(stamp);
102121
}
103-
104-
returncreateNativeTransform(ptrs,renderType,inFormatter,
105-
isInIntPacked,outFormatter,isOutIntPacked,disposerRef);
106122
}
107123

108124
privatestaticnativelongcreateNativeTransform(
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
importjava.awt.color.ColorSpace;
26+
importjava.awt.color.ICC_ColorSpace;
27+
importjava.awt.color.ICC_Profile;
28+
importjava.lang.reflect.Field;
29+
importjava.lang.reflect.Modifier;
30+
importjava.util.ArrayList;
31+
importjava.util.List;
32+
importjava.util.concurrent.TimeUnit;
33+
importjava.util.concurrent.atomic.AtomicBoolean;
34+
35+
/**
36+
* @test
37+
* @bug 8271718
38+
* @summary Verifies MT safety of color transformation while profile is changed
39+
*/
40+
publicfinalclassMTTransformReplacedProfile {
41+
42+
privatestaticvolatilelongendtime;
43+
44+
publicstaticvoidmain(String[]args)throwsException {
45+
ICC_Profile[]profiles = {
46+
ICC_Profile.getInstance(ColorSpace.CS_sRGB),
47+
ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB),
48+
ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ),
49+
ICC_Profile.getInstance(ColorSpace.CS_PYCC),
50+
ICC_Profile.getInstance(ColorSpace.CS_GRAY)
51+
};
52+
53+
List<Integer>tags =newArrayList<>();
54+
for (Fieldfield :ICC_Profile.class.getDeclaredFields()) {
55+
if (Modifier.isStatic(field.getModifiers())
56+
&&Modifier.isPublic(field.getModifiers())
57+
&&Modifier.isFinal(field.getModifiers())
58+
&&field.getType() ==int.class) {
59+
tags.add(field.getInt(null));
60+
}
61+
}
62+
63+
List<Thread>tasks =newArrayList<>();
64+
for (inttag :tags) {
65+
for (ICC_Profileprofile1 :profiles) {
66+
for (ICC_Profileprofile2 :profiles) {
67+
byte[]d1 =profile1.getData(tag);
68+
byte[]d2 =profile2.getData(tag);
69+
if (d1 ==null ||d2 ==null) {
70+
continue;
71+
}
72+
tasks.add(newThread(() -> {
73+
try {
74+
test(profile1.getData(),d1,d2,tag);
75+
}catch (Throwableignored) {
76+
// only the crash is the test failure
77+
}
78+
}));
79+
}
80+
}
81+
}
82+
83+
// Try to run the test no more than 15 seconds
84+
endtime =System.nanoTime() +TimeUnit.SECONDS.toNanos(15);
85+
for (Threadt :tasks) {
86+
t.start();
87+
}
88+
for (Threadt :tasks) {
89+
t.join();
90+
}
91+
}
92+
93+
privatestaticvoidtest(byte[]all,byte[]data1,byte[]data2,inttag)
94+
throwsException {
95+
ICC_Profileicc =ICC_Profile.getInstance(all);
96+
ColorSpacecs =newICC_ColorSpace(icc);
97+
AtomicBooleanstop =newAtomicBoolean();
98+
Threadswap =newThread(() -> {
99+
try {
100+
while (!isComplete()) {
101+
icc.setData(tag,data1);
102+
icc.setData(tag,data2);
103+
}
104+
}catch (Throwableignored) {
105+
// only the crash is the test failure
106+
}
107+
stop.set(true);
108+
});
109+
110+
float[]colorvalue =newfloat[3];
111+
Threadtransform =newThread(() -> {
112+
booleanrgb =true;
113+
while (!stop.get()) {
114+
try {
115+
if (rgb) {
116+
cs.toRGB(colorvalue);
117+
}else {
118+
cs.toCIEXYZ(colorvalue);
119+
}
120+
}catch (Throwableignored) {
121+
// only the crash is the test failure
122+
}
123+
rgb = !rgb;
124+
}
125+
});
126+
127+
swap.start();
128+
transform.start();
129+
swap.join();
130+
transform.join();
131+
}
132+
133+
privatestaticbooleanisComplete() {
134+
returnendtime -System.nanoTime() <0;
135+
}
136+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp