Skip to content

Conversation

@rruuaanng
Copy link
Contributor

@rruuaanng rruuaanng commented Nov 3, 2024

Actually, it only requires preprocessing the parameter passing. I hope it won't cause data type truncation.

cc @vstinner

// On Windows, timeval.tv_sec type is long
res2 = _PyTime_AsCLong(tv_sec, &tv->tv_sec);
#elif _UCRT
res2 = _PyTime_AsTime_t(tv_sec, (time_t *)&tv->tv_sec);
Copy link
Member

Choose a reason for hiding this comment

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

This is not the correct fix. From the error message "expected 'time_t *' {aka 'long long int *'} but argument is of type 'long int *'" it can be seen that tv->tv_sec has type long int which is different from long long int.

Copy link
Contributor Author

@rruuaanng rruuaanng Nov 3, 2024

Choose a reason for hiding this comment

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

Actually my initial thought was to start with struct timeval, but maybe that's not appropriate :(

Edit
(I actually think casting to the target type might be better than this.)

Edit2
Suddenly I remembered that struct timeval seems to be defined in the system header file.

@bedevere-app
Copy link

bedevere-app bot commented Nov 3, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@rruuaanng
Copy link
Contributor Author

rruuaanng commented Nov 3, 2024

Hmmm.... Maybe this problem cannot be solved fundamentally. Unless we start from the function signature. At least I think that casting might be the solution. The author gave a thumbs up as feedback :)

@serhiy-storchaka
Copy link
Member

Of course, it can be solved. You should just understand what this code do and what goes wrong. Find a function similar to _PyTime_AsTime_t that converts to long int. If it does not exist, look if there are other functions that convert to other integer types and write a similar code.

@rruuaanng
Copy link
Contributor Author

rruuaanng commented Nov 5, 2024

In fact, what I'm worried about is that although forced conversion can solve the problem, what if the number value is cut off. (Maybe not)

@serhiy-storchaka
Copy link
Member

No, it does not solve the problem. It creates a possible security issue (buffer overflow).

@erlend-aasland
Copy link
Contributor

@rruuaanng: please do not create PRs for half-baked solutions; try to understand the problem first, and only when you have a clear solution, propose a PR. Your pattern of opening PRs with half-baked solutions only result in wasting review resources, wasting CI resources, and polluting the PR list. I'm closing this.

@rruuaanng rruuaanng deleted the gh121427 branch November 6, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants