undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4228104
|
||||
* @summary Tests work of BODY BACKGROUND tag in HTML renderer
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual bug4228104
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class bug4228104 {
|
||||
static final String INSTRUCTIONS = """
|
||||
There should be an image displaying dukes under the rows of digits.
|
||||
If you can see it, the test PASSES. Otherwise, the test FAILS.
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("bug4228104 Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(40)
|
||||
.testUI(bug4228104::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
static JFrame createUI() {
|
||||
JFrame f = new JFrame("Background HTML Text Test");
|
||||
String dir = System.getProperty("test.src",
|
||||
System.getProperty("user.dir"));
|
||||
String htmlText1 =
|
||||
"<html><BODY BACKGROUND=\"file:" + dir
|
||||
+ "/duke.gif\">\n" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111" +
|
||||
"<br>111111111111111111";
|
||||
JLabel button1 = new JLabel(htmlText1);
|
||||
f.add(button1, BorderLayout.NORTH);
|
||||
f.setSize(200, 200);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/javax/swing/plaf/basic/BasicHTML/4228104/duke.gif
Normal file
BIN
test/jdk/javax/swing/plaf/basic/BasicHTML/4228104/duke.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
|
|
@ -0,0 +1,113 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 4251579
|
||||
* @summary Tests if style sheets are working in JLabel
|
||||
* @run main bug4251579
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Robot;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class bug4251579 {
|
||||
|
||||
private static JLabel htmlComponent;
|
||||
private static JFrame mainFrame;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final Robot robot = new Robot();
|
||||
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
createAndShowGUI();
|
||||
}
|
||||
});
|
||||
|
||||
robot.waitForIdle();
|
||||
robot.delay(1000);
|
||||
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
boolean passed = false;
|
||||
|
||||
Point p = htmlComponent.getLocationOnScreen();
|
||||
Dimension d = htmlComponent.getSize();
|
||||
int x0 = p.x;
|
||||
int y = p.y + d.height / 2;
|
||||
|
||||
for (int x = x0; x < x0 + d.width; x++) {
|
||||
if (robot.getPixelColor(x, y).equals(Color.blue)) {
|
||||
passed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
if (mainFrame != null) {
|
||||
mainFrame.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void createAndShowGUI() {
|
||||
|
||||
String htmlText =
|
||||
"<html>"
|
||||
+ "<head><style> .blue{ color:blue; } </style></head>"
|
||||
+ "<body"
|
||||
+ "<P class=\"blue\"> should be rendered with BLUE class definition</P>"
|
||||
+ "</body>";
|
||||
|
||||
mainFrame = new JFrame("bug4251579");
|
||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
htmlComponent = new JLabel(htmlText);
|
||||
mainFrame.getContentPane().add(htmlComponent);
|
||||
|
||||
mainFrame.setLocationRelativeTo(null);
|
||||
mainFrame.pack();
|
||||
mainFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 4960629 7124238
|
||||
* @summary Tests if font for html text on widgets in correct.
|
||||
* @author Denis Sharypov
|
||||
* @run main bug4960629
|
||||
*/
|
||||
|
||||
import java.awt.Font;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.basic.BasicHTML;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.View;
|
||||
import javax.swing.text.html.StyleSheet;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
|
||||
public class bug4960629 {
|
||||
private boolean passed = false;
|
||||
private JLabel label = null;
|
||||
private JFrame f = null;
|
||||
|
||||
public void createAndShowGUI() throws Exception {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||
label = new JLabel("<html><P>This is a test of the</P></html>");
|
||||
System.out.println("UIManager.getLookAndFeel()"
|
||||
+ UIManager.getLookAndFeel().getClass());
|
||||
f = new JFrame();
|
||||
f.getContentPane().add(label);
|
||||
f.pack();
|
||||
f.setVisible(true);
|
||||
test();
|
||||
} finally {
|
||||
if (f != null) { f.dispose(); }
|
||||
}
|
||||
}
|
||||
|
||||
bug4960629() throws InvocationTargetException, InterruptedException {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
createAndShowGUI();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Exception "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void test() {
|
||||
View root = ((View)label.getClientProperty(BasicHTML.propertyKey))
|
||||
.getView(0);
|
||||
int n = root.getViewCount();
|
||||
View v = root.getView(n - 1);
|
||||
AttributeSet attrs = v.getAttributes();
|
||||
StyleSheet ss = ((HTMLDocument) v.getDocument()).getStyleSheet();
|
||||
Font font = ss.getFont(attrs);
|
||||
System.out.println(font.getSize());
|
||||
passed = (font.getSize() == 12);
|
||||
if(!passed) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Throwable {
|
||||
new bug4960629();
|
||||
}
|
||||
}
|
||||
120
test/jdk/javax/swing/plaf/basic/BasicHTML/bug4248210.java
Normal file
120
test/jdk/javax/swing/plaf/basic/BasicHTML/bug4248210.java
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
|
||||
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4248210
|
||||
* @key headful
|
||||
* @summary Tests that HTML in JLabel is painted using LAF-defined
|
||||
foreground color
|
||||
* @run main bug4248210
|
||||
*/
|
||||
|
||||
public class bug4248210 {
|
||||
private static final Color labelColor = Color.red;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (UIManager.LookAndFeelInfo laf :
|
||||
UIManager.getInstalledLookAndFeels()) {
|
||||
if (!(laf.getName().contains("Motif") || laf.getName().contains("GTK"))) {
|
||||
System.out.println("Testing LAF: " + laf.getName());
|
||||
SwingUtilities.invokeAndWait(() -> test(laf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(UIManager.LookAndFeelInfo laf) {
|
||||
setLookAndFeel(laf);
|
||||
if (UIManager.getLookAndFeel() instanceof NimbusLookAndFeel) {
|
||||
// reset "basic" properties
|
||||
UIManager.getDefaults().put("Label.foreground", null);
|
||||
// set "synth - nimbus" properties
|
||||
UIManager.getDefaults().put("Label[Enabled].textForeground", labelColor);
|
||||
} else {
|
||||
// reset "synth - nimbus" properties
|
||||
UIManager.getDefaults().put("Label[Enabled].textForeground", null);
|
||||
// set "basic" properties
|
||||
UIManager.getDefaults().put("Label.foreground", labelColor);
|
||||
}
|
||||
|
||||
JLabel label = new JLabel("<html><body>\u2588 \u2588 \u2588 \u2588</body></html>");
|
||||
label.setSize(150, 30);
|
||||
|
||||
BufferedImage img = paintToImage(label);
|
||||
if (!chkImgForegroundColor(img)) {
|
||||
try {
|
||||
ImageIO.write(img, "png", new File("Label_" + laf.getName() + ".png"));
|
||||
} catch (IOException ignored) {}
|
||||
throw new RuntimeException("JLabel not painted with LAF defined " +
|
||||
"foreground color");
|
||||
}
|
||||
System.out.println("Test Passed");
|
||||
}
|
||||
|
||||
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(laf.getClassName());
|
||||
} catch (UnsupportedLookAndFeelException ignored) {
|
||||
System.out.println("Unsupported LAF: " + laf.getClassName());
|
||||
} catch (ClassNotFoundException | InstantiationException
|
||||
| IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage paintToImage(JComponent content) {
|
||||
BufferedImage im = new BufferedImage(content.getWidth(), content.getHeight(),
|
||||
TYPE_INT_RGB);
|
||||
Graphics2D g = (Graphics2D) im.getGraphics();
|
||||
g.setBackground(Color.WHITE);
|
||||
g.clearRect(0, 0, content.getWidth(), content.getHeight());
|
||||
content.paint(g);
|
||||
g.dispose();
|
||||
return im;
|
||||
}
|
||||
|
||||
private static boolean chkImgForegroundColor(BufferedImage img) {
|
||||
for (int x = 0; x < img.getWidth(); ++x) {
|
||||
for (int y = 0; y < img.getHeight(); ++y) {
|
||||
if (img.getRGB(x, y) == labelColor.getRGB()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue