-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
👋 Welcome back YaaZ! A progress list of the required criteria for merging this PR into |
Webrevs
|
There was a problem hiding this 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]; |
There was a problem hiding this comment.
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.
- 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 (!)
- 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
There was a problem hiding this comment.
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.
@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! |
There was a problem hiding this 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 ?
Please do, I only did manual testing |
Automated testing looks good. |
@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:
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
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 |
/sponsor |
Going to push as commit f842ec4.
Your commit was automatically rebased without conflicts. |
data
array has size ofMAX_BUFFER
likewname
, but it has a char type, so its size is twice smaller than actual path limit, because paths returned byRegEnumValueW
use wide chars. We need to double this limit.Progress
Issue
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