Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8286867: Update #getGlyphCode return a negative number #795

Closed
wants to merge 2 commits into from

Conversation

Tomator01
Copy link

@Tomator01 Tomator01 commented May 13, 2022

When I used BlueJ, I found a problem with Chinese display. /javafx.graphics/com/sun/javafx/font/CompositeGlyphMapper.java#getGlyphCode may return a negative number when no font library is specified in Linux,and this could cause java.lang.ArrayIndexOutOfBoundsException error.So javafx.graphics/com/sun/prism/impl/GlyphCache.java#getCachedGlyph shou check the glyphCode.
The crash demo like this:
`import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MenuExample extends Application {
public static void main(String[] args) {
launch(args);
}

@Override  
public void start(Stage primaryStage) throws Exception {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root,200,300);
    MenuBar menubar = new MenuBar();
    Menu FileMenu = new Menu("文本");
    MenuItem filemenu1=new MenuItem("新建");
    MenuItem filemenu2=new MenuItem("Save");  
    MenuItem filemenu3=new MenuItem("Exit");  
    Menu EditMenu=new Menu("Edit");  
    MenuItem EditMenu1=new MenuItem("Cut");  
    MenuItem EditMenu2=new MenuItem("Copy");  
    MenuItem EditMenu3=new MenuItem("Paste");  
    EditMenu.getItems().addAll(EditMenu1,EditMenu2,EditMenu3);  
    root.setTop(menubar);  
    FileMenu.getItems().addAll(filemenu1,filemenu2,filemenu3);  
    menubar.getMenus().addAll(FileMenu,EditMenu);  
    primaryStage.setScene(scene);  
    primaryStage.setTitle("TEST");
    primaryStage.show();  
      
}     

} `

the error:
java.lang.ArrayIndexOutOfBoundsException: Index -25 out of bounds for length 32 at com.sun.prism.impl.GlyphCache.getCachedGlyph(GlyphCache.java:332) at com.sun.prism.impl.GlyphCache.render(GlyphCache.java:148) at com.sun.prism.impl.ps.BaseShaderGraphics.drawString(BaseShaderGraphics.java:2101) at com.sun.javafx.sg.prism.NGText.renderText(NGText.java:312) at com.sun.javafx.sg.prism.NGText.renderContent2D(NGText.java:270) at com.sun.javafx.sg.prism.NGShape.renderContent(NGShape.java:261) at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072) at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964) at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270) at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578) at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072) at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964) at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270) at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578) at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072) at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964) at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270) at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578) at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072) at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964) at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270) at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578) at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072) at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964) at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270) at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578) at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072) at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964) at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:479) at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:328) at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Integration blocker

 ⚠️ Title mismatch between PR and JBS for issue JDK-8286867

Issue

  • JDK-8286867: CompositeGlyphMapper.java#getGlyphCode return a negative number ⚠️ Title mismatch between PR and JBS.

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/795/head:pull/795
$ git checkout pull/795

Update a local copy of the PR:
$ git checkout pull/795
$ git pull https://git.openjdk.org/jfx.git pull/795/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 795

View PR using the GUI difftool:
$ git pr show -t 795

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/795.diff

Webrev

Link to Webrev Comment

When I used BlueJ, I found a problem with Chinese display. /javafx.graphics/com/sun/javafx/font/CompositeGlyphMapper.java#getGlyphCode may return a negative number when no font library is specified in Linux,and this could cause java.lang.ArrayIndexOutOfBoundsException error.So javafx.graphics/com/sun/prism/impl/GlyphCache.java#getCachedGlyph  shou check the glyphCode.
@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label May 13, 2022
@bridgekeeper
Copy link

bridgekeeper bot commented May 13, 2022

Hi @Tomator01, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user Tomator01" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@Tomator01
Copy link
Author

Tomator01 commented May 13, 2022

The crash demo like this:
`import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MenuExample extends Application {
public static void main(String[] args) {
launch(args);
}

@Override  
public void start(Stage primaryStage) throws Exception {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root,200,300);
    MenuBar menubar = new MenuBar();
    Menu FileMenu = new Menu("文本");
    MenuItem filemenu1=new MenuItem("新建");
    MenuItem filemenu2=new MenuItem("Save");  
    MenuItem filemenu3=new MenuItem("Exit");  
    Menu EditMenu=new Menu("Edit");  
    MenuItem EditMenu1=new MenuItem("Cut");  
    MenuItem EditMenu2=new MenuItem("Copy");  
    MenuItem EditMenu3=new MenuItem("Paste");  
    EditMenu.getItems().addAll(EditMenu1,EditMenu2,EditMenu3);  
    root.setTop(menubar);  
    FileMenu.getItems().addAll(filemenu1,filemenu2,filemenu3);  
    menubar.getMenus().addAll(FileMenu,EditMenu);  
    primaryStage.setScene(scene);  
    primaryStage.setTitle("TEST");
    primaryStage.show();  
      
}     

}
`

@kevinrushforth
Copy link
Member

@Tomator01 thank you for your interest in contributing to the OpenJFX project.

In order for any comments that you add to this (or any other) PR to be retained, you will need to accept the OpenJDK Terms of Use as shown above. This is a one-time step.

Please read the CONTRIBUTING guidelines, in particular the Before submitting a pull request section, for steps needed to advance this pull request, including:

  • Sign and submit the OCA, then indicate that you have done so with the /signed command
  • Submit a bug report with a test case at bugreport.java.com

@kevinrushforth
Copy link
Member

I see that you already have submitted a bug report. You should get an email when it is made public.

@Tomator01
Copy link
Author

Tomator01 commented May 16, 2022

thanks,I'll wait for the bug

@Tomator01 Tomator01 changed the title Update GlyphCache.java 8286867: Update #getGlyphCode return a negative number May 17, 2022
@Tomator01
Copy link
Author

/signed

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label May 17, 2022
@bridgekeeper
Copy link

bridgekeeper bot commented May 17, 2022

Thank you! Please allow for up to two weeks to process your OCA, although it is usually done within one to two business days. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@Tomator01
Copy link
Author

@Tomator01 thank you for your interest in contributing to the OpenJFX project.

In order for any comments that you add to this (or any other) PR to be retained, you will need to accept the OpenJDK Terms of Use as shown above. This is a one-time step.

Please read the CONTRIBUTING guidelines, in particular the Before submitting a pull request section, for steps needed to advance this pull request, including:

  • Sign and submit the OCA, then indicate that you have done so with the /signed command
  • Submit a bug report with a test case at bugreport.java.com

Hello,i have signed oca ,and pull /signed command ,so I'm just wait for OCA to pass?

@yososs
Copy link

yososs commented May 17, 2022

Reading the author's description of this PR, one wonders why the added condition is not "glyphCode < 0".

if (glyphCode <= 0) {return null;}

@Tomator01
Copy link
Author

Reading the author's description of this PR, one wonders why the added condition is not "glyphCode < 0".

if (glyphCode <= 0) {return null;}

Your suggestion is right

@kevinrushforth
Copy link
Member

Hello,i have signed oca ,and pull /signed command ,so I'm just wait for OCA to pass?

Yes, at this point you wait for your OCA to be processed.

@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels May 18, 2022
@openjdk openjdk bot added the rfr Ready for review label May 18, 2022
@mlbridge
Copy link

mlbridge bot commented May 18, 2022

Webrevs

@Tomator01
Copy link
Author

I can repeated this issue on uos when the linux doesn't have /usr/share/fonts/wps-office/FZSongS_20100603.TTF file ,openjfx version 11,method getGlyphCode will return a negative number

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a question and style comment inline.

Can you provide an automated test case, or if that's not possible, a manual test case?

@@ -239,6 +239,8 @@ private void clearAll() {
}

private GlyphData getCachedGlyph(int glyphCode, int subPixel) {
if (glyphCode < 0) {return null;}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you ensured that all callers are prepared to deal with a null return value?

Minor: Please format this according to code conventions:

        if (glyphCode < 0) {
            return null;
        }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`if (!packer.add(rect)) { if (PULSE_LOGGING_ENABLED) { PulseLogger.incrementCounter("Font Glyph Cache Cleared"); } // If add fails,clear up the cache. Try add again. clearAll(); if (!packer.add(rect)) { if (PrismSettings.verbose) { System.out.println(rect + " won't fit in GlyphCache"); } return null; } }

`
The line 298 also return null,so return nul is ok

@kevinrushforth kevinrushforth self-requested a review June 30, 2022 20:16
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 31, 2023

@Tomator01 This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 29, 2023

@Tomator01 This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Ready for review
3 participants