Tk Source Code

View Ticket
Login
2025-02-14
15:29
Revert part of [269ce15793561e10]: Backport fix for [080a28104e] and add TK_NO_STDERR processing, but not the solution itself. Github testcases are already broken for 2 weaks, it appears focus-1.12 and focus-1.19 are negatively affected by this closed check-in: c4d8503c user: jan.nijtmans tags: mistake
2025-01-27
15:34
Backport fix for [080a28104e] and add TK_NO_STDERR processing. check-in: 269ce157 user: culler tags: core-8-6-branch
2025-01-25
11:41
(cherry-pick): Fix [080a28104e]: Fixes crash caused by nil UTType when user provides a bogus file type check-in: 3136e2b8 user: jan.nijtmans tags: core-8-branch
2025-01-24
18:58 • Closed ticket [080a2810]: tk_getOpenFile crash on macOS plus 6 other changes artifact: 7e77191b user: marc_culler
2025-01-21
15:47
Fix [080a28104e]: crash caused by nil UTType when user provides a bogus file type. check-in: ce3d0b20 user: culler tags: bug-080a28104e
15:25 • Pending ticket [080a2810]: tk_getOpenFile crash on macOS plus 6 other changes artifact: 1f109a8f user: marc_culler
2025-01-08
10:00 • Ticket [080a2810]: 3 changes artifact: 88a98fb2 user: anonymous
09:49 • New ticket [080a2810]. artifact: 37905894 user: anonymous

Ticket UUID: 080a28104e25e054f8f5869d9333aa57c221b896
Title: tk_getOpenFile crash on macOS
Type: Bug Version: trunk
Submitter: anonymous Created on: 2025-01-08 09:49:37
Subsystem: 37. [tk_get*File] Assigned To: marc_culler
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2025-01-24 18:58:22
Resolution: Fixed Closed By: marc_culler
    Closed on: 2025-01-24 18:58:22
Description:
The following code crash on macOS (Darwin Kernel Version 24.2.0):

package require Tk
set filename [tk_getOpenFile -filetypes {
    {"Weird Text" {weird.txt}}
    {"All files" {*}}
}]

It is necessary to check the value returned by typeWithFilenameExtension (https://developer.apple.com/documentation/foundation/nsmutablearray/1411274-addobject):

--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -37,7 +37,8 @@ static void setAllowedFileTypes(
        NSMutableArray<UTType *> *allowedTypes = [NSMutableArray array];
        for (NSString *ext in extensions) {
            UTType *uttype = [UTType typeWithFilenameExtension: ext];
-           [allowedTypes addObject:uttype];
+           if (uttype)
+               [allowedTypes addObject:uttype];
        }
        [panel setAllowedContentTypes:allowedTypes];
     } else {
User Comments: marc_culler (claiming to be Marc Culler) added on 2025-01-24 18:58:22:
The patch and a non-regression test have been merged into trunk.

marc_culler (claiming to be Marc Culler) added on 2025-01-21 15:25:00:
I can reproduce this crash on macOS 15.1 with kernel 24.1.0 and I
confirm that it does not occur after your patch.

I will commit the change in a bugfix branch to give the CI runner a
chance to check it, and work on adding a non-regression test.  Your
sample code should be easy to use as a test.

Thanks!