#24 ✓resolved
jcburns

JSTalk Editor crash when NSArray index beyond bounds.

Reported by jcburns | December 27th, 2009 @ 09:13 PM

Create an NSArray of 30 objects. Try to reference object 31 ([TheArray objectAtIndex:31]). JSTalk Editor itself crashes.
Console is filled with this helpful stuff:

12/28/09 12:08:59 AM JSTalk Editor[27832] An uncaught exception was raised
12/28/09 12:08:59 AM JSTalk Editor[27832] -[NSCFArray objectAtIndex:]: index (165) beyond bounds (164)
12/28/09 12:08:59 AM JSTalk Editor[27832]
Terminating app due to uncaught exception 'NSRangeException', reason: ' -[NSCFArray objectAtIndex:]: index (165) beyond bounds (164)'
Call stack at first throw: (

0   CoreFoundation                      0x00007fff813f3444 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x00007fff889c50f3 objc_exception_throw + 45
2   CoreFoundation                      0x00007fff813f3267 +[NSException raise:format:arguments:] + 103
3   CoreFoundation                      0x00007fff813f31f4 +[NSException raise:format:] + 148
4   Foundation                          0x00007fff875fa080 _NSArrayRaiseBoundException + 122
5   Foundation                          0x00007fff8755cb81 -[NSCFArray objectAtIndex:] + 75
6   libffi.dylib                        0x00007fff87f99e24 ffi_call_unix64 + 76
7   ???                                 0x00000001005d2bd0 0x0 + 4301073360

) 12/28/09 12:08:59 AM [0x0-0x5a75a7].org.jstalk.JSTalkEditor[27832] terminate called after throwing an instance of 'NSException'
12/28/09 12:08:59 AM [0x0-0x5a75a7].org.jstalk.JSTalkEditor[27832] LP64!
12/28/09 12:08:59 AM [0x0-0x5a75a7].org.jstalk.JSTalkEditor[27832] 32

Comments and changes to this ticket

  • gus (at flyingmeat)

    gus (at flyingmeat) December 29th, 2009 @ 12:43 PM

    So this is a really weird thing. For some reason the try/catch block I've got doesn't handle this case, and I don't know why. It seems that when you get into ffi land, the normal rules just don't apply.

    This has bothered me for a while as well, so I'll see what I can do to fix it.

  • gus (at flyingmeat)

    gus (at flyingmeat) December 29th, 2009 @ 02:09 PM

    After a bit of digging, looks like this is a bug in the 64 bit version of libffi. I found this in pyobjc's release notes:
    NOTE: 64-bit support does not yet work on PPC due to a bug in libffi which prevents catching Objective-C exceptions

    And sure enough, everything works ok in 32 bit mode.

  • gus (at flyingmeat)

    gus (at flyingmeat) December 29th, 2009 @ 03:07 PM

    Actually, I'm an idiot. I can fix this:

    if (prep_status == FFI_OK)

    {
        @try {
            void* storage = [returnValue storage];
            if ([returnValue ffi_type] == &ffi_type_void)   storage = NULL;
            //      log_ffi_call(&cif, values, callAddress);
            ffi_call(&cif, callAddress, storage, values);
        }
        @catch (NSException *e) {
            debug(@"%s:%d", __FUNCTION__, __LINE__);
            throwException(ctx, exception, [e description]);
            return 0x00;
    

    need to get that into JSCocoa...

  • jcburns

    jcburns December 29th, 2009 @ 03:12 PM

    You look at something like JSTalk (or JSCocoa) and say "boy, what a clever pulling together of so many powerful libraries." But of course, when one tiny issue is causing trouble way, way down the chain, it really increases the number of possible ways you can be screwed outside your control.

  • gus (at flyingmeat)

    gus (at flyingmeat) December 29th, 2009 @ 03:32 PM

    Yea :)

    Anyway, the latest build of JSTalk has this fix:
    http://jstalk.org/

    Still need to get it in JSCocoa though (and probably only for 64 bit)

  • Patrick Geiller

    Patrick Geiller December 29th, 2009 @ 09:30 PM

    The latest JSCocoa checks for exceptions, please upgrade :)

  • gus (at flyingmeat)

    gus (at flyingmeat) December 30th, 2009 @ 11:21 AM

    • State changed from “new” to “resolved”

    Alright, updated to the latest jscocoa, and the fix is in.

    danke!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Check out the readme: http://github.com/ccgus/jstalk/tree/master

People watching this ticket

Pages