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

8305667: Some fonts installed in user directory are not detected on Windows #13359

Closed
wants to merge 2 commits into from

Conversation

YaaZ
Copy link
Member

@YaaZ YaaZ commented Apr 5, 2023

data array has size of MAX_BUFFER like wname, but it has a char type, so its size is twice smaller than actual path limit, because paths returned by RegEnumValueW use wide chars. We need to double this limit.


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

Issue

  • JDK-8305667: Some fonts installed in user directory are not detected on Windows (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13359

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13359.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 5, 2023

👋 Welcome back YaaZ! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 5, 2023
@openjdk
Copy link

openjdk bot commented Apr 5, 2023

@YaaZ The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Apr 5, 2023
@mlbridge
Copy link

mlbridge bot commented Apr 5, 2023

Webrevs

Copy link
Contributor

@avu avu left a comment

Choose a reason for hiding this comment

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

Looks good

#define MAX_NAME_BUFFER (MAX_PATH+1)
#define MAX_DATA_BUFFER (MAX_PATH*2+2)
const wchar_t wname[MAX_NAME_BUFFER];
const char data[MAX_DATA_BUFFER];
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this I think we need to do more here and forget using the fixed buffer sizes and use what the query returns.

Let's consider NAME and DATA one at a time.

  1. NAME
    First note that we call the "W" version of the function so anything that is a string will be measured in wchars, not bytes
    NAME is a string so the value we get back is the number of chars in the string.
    Since we allocate using wchar_t we are OK there.
    But we also need to note that the returned len doesn't include the terminating null.
    So it seems to me that we need to adjust the check
    dwMaxValueNameLen >= MAX_NAME_BUFFER

However going back to NAME the maximum name len has nothing to do with file paths.
So FILENAME_MAX and MAX_PATH are completely irrelevant and the code shouldn't be using it for NAME.
If there's a TTC with 10 fonts in it the name will look like
"NAME_XXXXXXXXXXXXXX_1 & NAME_XXXXXXXXXXX_2 & ... ...... & NAME_XXXXXXXXXXXX10 ... (TrueType)"
then we can exceed FILENAME_MAX and MAX_PATH very easily.
[BTW I checked and FILENAME_MAX and MAX_PATH are both 260]

So I think we need to dynamically allocate the buffer based on the returned value of dwMaxValueNameLen
which does NOT include the terminating NULL.

So I'd want code like
wname = (wchar_t*)(calloc(dwMaxValueNameLen+1, sizeof(wchar_t))

and then remember to add code to free wname (!)

  1. DATA
    Since FILENAME_MAX and MAX_PATH are both 260, the current proposal doesn't change anything for NAME.
    However it doubles the allocation for DATA. I can see why this is needed.
    I see that for user installed fonts the registry value is the whole path (folder path + filename) ,
    whereas for the installed fonts for which this was "designed" it is just the file name.
    But why use the hard coded value when the registry call already told us what we need ?

RegQueryInfoKeyW specifies that it returns the data length in BYTES.
However we know its a unicode string, so depending how we allocate the array
its either len or len/2 - if its wchar_t.

wchar_t data = (wchar_t)(calloc(dwMaxValueNameLen, sizeof(char))

  • we already cast to LPWSTR so why not make it a wchar_t anyway ?

  • I used calloc just to be paranoid to get zeroed out memory

  • I tested and can confirm that for DATA the returned len includes the allocation for the terminating null.

  • remember to free this too

  • With this dynamic allocation we no longer need the checks on lines 544/545

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to dynamic allocation as you suggested. Though I used malloc, because it seems to be used more common across JDK code.

@bridgekeeper
Copy link

bridgekeeper bot commented May 24, 2023

@YaaZ 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!

@YaaZ YaaZ requested a review from prrace June 13, 2023 14:40
Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

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

So this looks good to me, but I want to run all our automated tests - I don't suppose you did that already ?

@YaaZ
Copy link
Member Author

YaaZ commented Jun 24, 2023

Please do, I only did manual testing

@prrace
Copy link
Contributor

prrace commented Jun 27, 2023

Automated testing looks good.

@openjdk
Copy link

openjdk bot commented Jun 27, 2023

@YaaZ This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8305667: Some fonts installed in user directory are not detected on Windows

Reviewed-by: avu, prr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 1195 new commits pushed to the master branch:

  • e3f18af: 8311007: jdk/jfr/tool/TestView.java can't find event
  • 08c51f2: 8310920: Fix -Wconversion warnings in command line flags
  • c2e9485: 8310921: Fix -Wconversion warnings from GenerateOopMap
  • ef71c32: 8310110: Shenandoah: Trace page sizes
  • c3f10e8: 8307625: Redundant receiver null check in LibraryCallKit::generate_method_call
  • 39c104d: 8310380: Handle problems in core-related tests on macOS when codesign tool does not work
  • 526dba1: 8310130: C2: assert(false) failed: scalar_input is neither phi nor a matchin reduction
  • 48e61c1: 8310728: Enable Zc:inline flag in Visual Studio build
  • 56a73a6: 8309591: Socket.setOption(TCP_QUICKACK) uses wrong level
  • afdaa2a: 8309109: AArch64: [TESTBUG] compiler/intrinsics/sha/cli/TestUseSHA3IntrinsicsOptionOnSupportedCPU.java fails on Neoverse N2 and V1
  • ... and 1185 more: https://git.openjdk.org/jdk/compare/5919fad1f4969ef3faaa0e8fe60ed6e4e15e5cff...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@avu, @prrace) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 27, 2023
@YaaZ
Copy link
Member Author

YaaZ commented Jun 28, 2023

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 28, 2023
@openjdk
Copy link

openjdk bot commented Jun 28, 2023

@YaaZ
Your change (at version d6218b5) is now ready to be sponsored by a Committer.

@avu
Copy link
Contributor

avu commented Jun 29, 2023

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 29, 2023

Going to push as commit f842ec4.
Since your change was applied there have been 1217 commits pushed to the master branch:

  • 690d626: 8307927: C2: "malformed control flow" with irreducible loop
  • be64d3a: 8310299: C2: 8275201 broke constant folding of array store check in some cases
  • b2eae16: 8295191: IR framework timeout options expect ms instead of s
  • af319d9: 8311064: Windows builds fail without precompiled headers after JDK-8310728
  • cbf418a: 8311020: Typo cleanup in Classfile API
  • f4b900b: 8310902: (fc) FileChannel.transferXXX async close and interrupt issues
  • cf8d706: 8308463: Refactor regenerated class handling in lambdaFormInvokers.cpp
  • 6f58ab2: 8301569: jmod list option and jimage list --help not interpreted correctly on turkish locale
  • 8f5a384: 8311032: Empty value for java.protocol.handler.pkgs system property can lead to unnecessary classloading attempts of protocol handlers
  • ded1370: 8309811: BytecodePrinter cannot handle unlinked classes
  • ... and 1207 more: https://git.openjdk.org/jdk/compare/5919fad1f4969ef3faaa0e8fe60ed6e4e15e5cff...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 29, 2023
@openjdk openjdk bot closed this Jun 29, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jun 29, 2023
@openjdk
Copy link

openjdk bot commented Jun 29, 2023

@avu @YaaZ Pushed as commit f842ec4.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants