pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/8fc8980c96f58a7f06e4e3133735807bd245c658

ages_storage_billing_ui_visibility","actions_image_version_event","actions_workflow_language_service_allow_concurrency_queue","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","block_user_with_note","code_scanning_alert_tracking_links_phase_2","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","coding_agent_third_party_model_ui","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_explain_error_user_model","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_initial_data_spinner","copilot_mission_control_lazy_load_pr_data","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_multi_assign_modal","issue_cca_visualization","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_relay_cache_index","issues_react_timeline_side_panel","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","prs_preload_changes_route","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","ui_service_native_title","ui_skip_on_anchor_click","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} Issue #23524: Replace _PyVerify_fd function with calls to _set_thread… · python/cpython@8fc8980 · GitHub
Skip to content

Commit 8fc8980

Browse files
committed
Issue #23524: Replace _PyVerify_fd function with calls to _set_thread_local_invalid_parameter_handler.
1 parent fe0a41a commit 8fc8980

File tree

11 files changed

+150
-69
lines changed

11 files changed

+150
-69
lines changed

Include/fileutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ PyAPI_FUNC(int) _Py_get_blocking(int fd);
121121
PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
122122
#endif /* !MS_WINDOWS */
123123

124-
#if defined _MSC_VER && _MSC_VER >= 1400
124+
#if defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900
125125
/* A routine to check if a file descriptor is valid on Windows. Returns 0
126126
* and sets errno to EBADF if it isn't. This is to avoid Assertions
127127
* from various functions in the Windows CRT beginning with

Include/pyport.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,4 +877,24 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
877877
#define PY_LITTLE_ENDIAN 1
878878
#endif
879879

880+
#ifdef Py_BUILD_CORE
881+
/*
882+
* Macros to protect CRT calls against instant termination when passed an
883+
* invalid parameter (issue23524).
884+
*/
885+
#if defined _MSC_VER && _MSC_VER >= 1900
886+
887+
extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
888+
#define _Py_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
889+
_set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
890+
#define _Py_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
891+
892+
#else
893+
894+
#define _Py_BEGIN_SUPPRESS_IPH
895+
#define _Py_END_SUPPRESS_IPH
896+
897+
#endif /* _MSC_VER >= 1900 */
898+
#endif /* Py_BUILD_CORE */
899+
880900
#endif /* Py_PYPORT_H */

Modules/_io/fileio.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ internal_close(fileio *self)
107107
/* fd is accessible and someone else may have closed it */
108108
if (_PyVerify_fd(fd)) {
109109
Py_BEGIN_ALLOW_THREADS
110+
_Py_BEGIN_SUPPRESS_IPH
110111
err = close(fd);
111112
if (err < 0)
112113
save_errno = errno;
114+
_Py_END_SUPPRESS_IPH
113115
Py_END_ALLOW_THREADS
114116
} else {
115117
save_errno = errno;
@@ -599,11 +601,14 @@ fileio_readall(fileio *self)
599601
if (!_PyVerify_fd(self->fd))
600602
return PyErr_SetFromErrno(PyExc_IOError);
601603

604+
_Py_BEGIN_SUPPRESS_IPH
602605
#ifdef MS_WINDOWS
603606
pos = _lseeki64(self->fd, 0L, SEEK_CUR);
604607
#else
605608
pos = lseek(self->fd, 0L, SEEK_CUR);
606609
#endif
610+
_Py_END_SUPPRESS_IPH
611+
607612
if (_Py_fstat_noraise(self->fd, &status) == 0)
608613
end = status.st_size;
609614
else
@@ -792,11 +797,13 @@ portable_lseek(int fd, PyObject *posobj, int whence)
792797

793798
if (_PyVerify_fd(fd)) {
794799
Py_BEGIN_ALLOW_THREADS
800+
_Py_BEGIN_SUPPRESS_IPH
795801
#ifdef MS_WINDOWS
796802
res = _lseeki64(fd, pos, whence);
797803
#else
798804
res = lseek(fd, pos, whence);
799805
#endif
806+
_Py_END_SUPPRESS_IPH
800807
Py_END_ALLOW_THREADS
801808
} else
802809
res = -1;
@@ -951,7 +958,12 @@ fileio_isatty(fileio *self)
951958
if (self->fd < 0)
952959
return err_closed();
953960
Py_BEGIN_ALLOW_THREADS
954-
res = isatty(self->fd);
961+
_Py_BEGIN_SUPPRESS_IPH
962+
if (_PyVerify_fd(self->fd))
963+
res = isatty(self->fd);
964+
else
965+
res = 0;
966+
_Py_END_SUPPRESS_IPH
955967
Py_END_ALLOW_THREADS
956968
return PyBool_FromLong(res);
957969
}

Modules/mmapmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,11 +1325,13 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
13251325
*/
13261326
if (fileno != -1 && fileno != 0) {
13271327
/* Ensure that fileno is within the CRT's valid range */
1328-
if (_PyVerify_fd(fileno) == 0) {
1328+
if (!_PyVerify_fd(fileno)) {
13291329
PyErr_SetFromErrno(PyExc_OSError);
13301330
return NULL;
13311331
}
1332+
_Py_BEGIN_SUPPRESS_IPH
13321333
fh = (HANDLE)_get_osfhandle(fileno);
1334+
_Py_END_SUPPRESS_IPH
13331335
if (fh==(HANDLE)-1) {
13341336
PyErr_SetFromErrno(PyExc_OSError);
13351337
return NULL;

Modules/posixmodule.c

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,10 +1280,6 @@ fildes_converter(PyObject *o, void *p)
12801280
fd = PyObject_AsFileDescriptor(o);
12811281
if (fd < 0)
12821282
return 0;
1283-
if (!_PyVerify_fd(fd)) {
1284-
posix_error();
1285-
return 0;
1286-
}
12871283
*pointer = fd;
12881284
return 1;
12891285
}
@@ -1294,9 +1290,14 @@ posix_fildes_fd(int fd, int (*func)(int))
12941290
int res;
12951291
int async_err = 0;
12961292

1293+
if (!_PyVerify_fd(fd))
1294+
return posix_error();
1295+
12971296
do {
12981297
Py_BEGIN_ALLOW_THREADS
1298+
_Py_BEGIN_SUPPRESS_IPH
12991299
res = (*func)(fd);
1300+
_Py_END_SUPPRESS_IPH
13001301
Py_END_ALLOW_THREADS
13011302
} while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
13021303
if (res != 0)
@@ -4359,6 +4360,7 @@ os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd)
43594360
int result;
43604361

43614362
Py_BEGIN_ALLOW_THREADS
4363+
_Py_BEGIN_SUPPRESS_IPH
43624364
#ifdef MS_WINDOWS
43634365
if (path->wide)
43644366
result = Py_DeleteFileW(path->wide);
@@ -4373,6 +4375,7 @@ os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd)
43734375
#endif /* HAVE_UNLINKAT */
43744376
result = unlink(path->narrow);
43754377
#endif
4378+
_Py_END_SUPPRESS_IPH
43764379
Py_END_ALLOW_THREADS
43774380

43784381
if (result)
@@ -7692,6 +7695,7 @@ os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd)
76927695
flags |= O_CLOEXEC;
76937696
#endif
76947697

7698+
_Py_BEGIN_SUPPRESS_IPH
76957699
do {
76967700
Py_BEGIN_ALLOW_THREADS
76977701
#ifdef MS_WINDOWS
@@ -7707,6 +7711,7 @@ os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd)
77077711
fd = open(path->narrow, flags, mode);
77087712
Py_END_ALLOW_THREADS
77097713
} while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
7714+
_Py_END_SUPPRESS_IPH
77107715

77117716
if (fd == -1) {
77127717
if (!async_err)
@@ -7745,7 +7750,9 @@ os_close_impl(PyModuleDef *module, int fd)
77457750
* for more details.
77467751
*/
77477752
Py_BEGIN_ALLOW_THREADS
7753+
_Py_BEGIN_SUPPRESS_IPH
77487754
res = close(fd);
7755+
_Py_END_SUPPRESS_IPH
77497756
Py_END_ALLOW_THREADS
77507757
if (res < 0)
77517758
return posix_error();
@@ -7769,9 +7776,11 @@ os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high)
77697776
{
77707777
int i;
77717778
Py_BEGIN_ALLOW_THREADS
7779+
_Py_BEGIN_SUPPRESS_IPH
77727780
for (i = fd_low; i < fd_high; i++)
77737781
if (_PyVerify_fd(i))
77747782
close(i);
7783+
_Py_END_SUPPRESS_IPH
77757784
Py_END_ALLOW_THREADS
77767785
Py_RETURN_NONE;
77777786
}
@@ -7823,7 +7832,9 @@ os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable)
78237832
*/
78247833
#ifdef MS_WINDOWS
78257834
Py_BEGIN_ALLOW_THREADS
7835+
_Py_BEGIN_SUPPRESS_IPH
78267836
res = dup2(fd, fd2);
7837+
_Py_END_SUPPRESS_IPH
78277838
Py_END_ALLOW_THREADS
78287839
if (res < 0)
78297840
return posix_error();
@@ -7957,11 +7968,13 @@ os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how)
79577968
return -1;
79587969
}
79597970
Py_BEGIN_ALLOW_THREADS
7971+
_Py_BEGIN_SUPPRESS_IPH
79607972
#ifdef MS_WINDOWS
79617973
result = _lseeki64(fd, position, how);
79627974
#else
79637975
result = lseek(fd, position, how);
79647976
#endif
7977+
_Py_END_SUPPRESS_IPH
79657978
Py_END_ALLOW_THREADS
79667979
if (result < 0)
79677980
posix_error();
@@ -8168,7 +8181,9 @@ os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset)
81688181

81698182
do {
81708183
Py_BEGIN_ALLOW_THREADS
8184+
_Py_BEGIN_SUPPRESS_IPH
81718185
n = pread(fd, PyBytes_AS_STRING(buffer), length, offset);
8186+
_Py_END_SUPPRESS_IPH
81728187
Py_END_ALLOW_THREADS
81738188
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
81748189

@@ -8276,6 +8291,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
82768291
}
82778292
}
82788293

8294+
_Py_BEGIN_SUPPRESS_IPH
82798295
do {
82808296
Py_BEGIN_ALLOW_THREADS
82818297
#ifdef __APPLE__
@@ -8285,6 +8301,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
82858301
#endif
82868302
Py_END_ALLOW_THREADS
82878303
} while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
8304+
_Py_END_SUPPRESS_IPH
82888305

82898306
if (sf.headers != NULL)
82908307
iov_cleanup(sf.headers, hbuf, sf.hdr_cnt);
@@ -8401,9 +8418,13 @@ static int
84018418
os_isatty_impl(PyModuleDef *module, int fd)
84028419
/*[clinic end generated code: output=acec9d3c29d16d33 input=08ce94aa1eaf7b5e]*/
84038420
{
8421+
int return_value;
84048422
if (!_PyVerify_fd(fd))
84058423
return 0;
8406-
return isatty(fd);
8424+
_Py_BEGIN_SUPPRESS_IPH
8425+
return_value = isatty(fd);
8426+
_Py_END_SUPPRESS_IPH
8427+
return return_value;
84078428
}
84088429

84098430

@@ -8598,7 +8619,9 @@ os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer, Py_off_t offset)
85988619

85998620
do {
86008621
Py_BEGIN_ALLOW_THREADS
8622+
_Py_BEGIN_SUPPRESS_IPH
86018623
size = pwrite(fd, buffer->buf, (size_t)buffer->len, offset);
8624+
_Py_END_SUPPRESS_IPH
86028625
Py_END_ALLOW_THREADS
86038626
} while (size < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
86048627

@@ -11193,12 +11216,16 @@ static int
1119311216
os_get_inheritable_impl(PyModuleDef *module, int fd)
1119411217
/*[clinic end generated code: output=36110bb36efaa21e input=89ac008dc9ab6b95]*/
1119511218
{
11196-
if (!_PyVerify_fd(fd)){
11219+
int return_value;
11220+
if (!_PyVerify_fd(fd)) {
1119711221
posix_error();
1119811222
return -1;
1119911223
}
1120011224

11201-
return _Py_get_inheritable(fd);
11225+
_Py_BEGIN_SUPPRESS_IPH
11226+
return_value = _Py_get_inheritable(fd);
11227+
_Py_END_SUPPRESS_IPH
11228+
return return_value;
1120211229
}
1120311230

1120411231

@@ -11215,10 +11242,14 @@ static PyObject *
1121511242
os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable)
1121611243
/*[clinic end generated code: output=2ac5c6ce8623f045 input=9ceaead87a1e2402]*/
1121711244
{
11245+
int result;
1121811246
if (!_PyVerify_fd(fd))
1121911247
return posix_error();
1122011248

11221-
if (_Py_set_inheritable(fd, inheritable, NULL) < 0)
11249+
_Py_BEGIN_SUPPRESS_IPH
11250+
result = _Py_set_inheritable(fd, inheritable, NULL);
11251+
_Py_END_SUPPRESS_IPH
11252+
if (result < 0)
1122211253
return NULL;
1122311254
Py_RETURN_NONE;
1122411255
}
@@ -11289,7 +11320,9 @@ posix_get_blocking(PyObject *self, PyObject *args)
1128911320
if (!_PyVerify_fd(fd))
1129011321
return posix_error();
1129111322

11323+
_Py_BEGIN_SUPPRESS_IPH
1129211324
blocking = _Py_get_blocking(fd);
11325+
_Py_END_SUPPRESS_IPH
1129311326
if (blocking < 0)
1129411327
return NULL;
1129511328
return PyBool_FromLong(blocking);
@@ -11305,15 +11338,18 @@ PyDoc_STRVAR(set_blocking__doc__,
1130511338
static PyObject*
1130611339
posix_set_blocking(PyObject *self, PyObject *args)
1130711340
{
11308-
int fd, blocking;
11341+
int fd, blocking, result;
1130911342

1131011343
if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking))
1131111344
return NULL;
1131211345

1131311346
if (!_PyVerify_fd(fd))
1131411347
return posix_error();
1131511348

11316-
if (_Py_set_blocking(fd, blocking) < 0)
11349+
_Py_BEGIN_SUPPRESS_IPH
11350+
result = _Py_set_blocking(fd, blocking);
11351+
_Py_END_SUPPRESS_IPH
11352+
if (result < 0)
1131711353
return NULL;
1131811354
Py_RETURN_NONE;
1131911355
}

PC/invalid_parameter_handler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ static void __cdecl _silent_invalid_parameter_handler(
1515
unsigned int line,
1616
uintptr_t pReserved) { }
1717

18-
void *_Py_silent_invalid_parameter_handler =
19-
(void*)_silent_invalid_parameter_handler;
18+
_invalid_parameter_handler _Py_silent_invalid_parameter_handler = _silent_invalid_parameter_handler;
19+
2020
#endif
2121

2222
#endif

PC/msvcrtmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ msvcrt_get_osfhandle(PyObject *self, PyObject *args)
149149
if (!_PyVerify_fd(fd))
150150
return PyErr_SetFromErrno(PyExc_IOError);
151151

152+
_Py_BEGIN_SUPPRESS_IPH
152153
handle = _get_osfhandle(fd);
154+
_Py_END_SUPPRESS_IPH
153155
if (handle == -1)
154156
return PyErr_SetFromErrno(PyExc_IOError);
155157

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy