Skip to content
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

[Bug] segmentation fault on listing the windows t-rec -l #4

Closed
ghost opened this issue Oct 11, 2020 · 19 comments
Closed

[Bug] segmentation fault on listing the windows t-rec -l #4

ghost opened this issue Oct 11, 2020 · 19 comments
Assignees
Labels
Type: Bug Something isn't working
Milestone

Comments

@ghost
Copy link

ghost commented Oct 11, 2020

Describe the bug
Whenever I run t-rec, it causes segmentation fault error. t-rec /bin/sh results same.

To Reproduce
Steps to reproduce the behavior:

  1. Run t-rec.

Expected behavior
It doesn't cause segmentation fault, and run correctly.

Screenshots
ss

  • Interestingly, as you see it leads error zsh: error on TTY read: Input/output error if you specified zsh, bash. However, sh won't lead this error.

Desktop (please complete the following information):

  • OS: MacOS
  • Version: 10.15.7
  • Zsh: zsh 5.8 (x86_64-apple-darwin19.3.0)
  • sh: version 3.2.57(1)-release (x86_64-apple-darwin19)
  • bash: version 3.2.57(1)-release (x86_64-apple-darwin19)

Additional context

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

Could you please also share the graphics card on your mac? Like from "About this Mac" > "Displays"

@ghost
Copy link
Author

ghost commented Oct 11, 2020

@sassman
Sure.

Displays: 
Built-in Display
2-inch (2304 x 1440)
Intel HD Graphics 615 1536 MB graphics

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

@Ryuta69 thanks. Also maybe you can check for some headers on your system: grep CGWindowListCopyWindowInfo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Versions/Current/Headers/*.h

And run t-rec -l and see if it lists you some windows with name and id. I suspect an issue with calling native osx core-graphics library functions on your system.

@ghost
Copy link
Author

ghost commented Oct 11, 2020

@sassman
Sure

  • headers on my system
// /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Versions/Current/Headers/CGWindow.h

/* Return an array of window dictionaries for windows within the user
   session.

   This function returns NULL if the caller is not running within a Quartz
   GUI session or the window server is disabled. You should release the
   array when you are finished using it. */

CG_EXTERN CFArrayRef __nullable CGWindowListCopyWindowInfo(CGWindowListOption option,
    CGWindowID relativeToWindow)
    CG_AVAILABLE_STARTING(10.5);
  • Run t-rec -l
zsh$ t-rec -l
Window | Id
zsh: illegal hardware instruction  t-rec -l

bash-3.2$ t-rec -l
Window | Id
Segmentation fault: 11

sh-3.2$ t-rec -l
Window | Id
Segmentation fault: 11

I'm afraid but I don't clearly get this means. But Segmentation fault: 11 means Memory Access Error. Maybe it didn't get any window/id, so accessing empty...?

-- P.S.
If this issue is because of my graphic card, I'll close this issue.

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

Very interesting, seems that is somehow graphics card related. But actually this whole crash should be prevented. So I will dig into that deeper.

One last thing I've noticed, when the mac screen recording permission are not granted, then the app also misbehaves, can you check that iTerm for example is authorized with a checkbox there:

image

@sassman sassman added Type: Bug Something isn't working HW: Intel HD Graphics 615 labels Oct 11, 2020
@sassman sassman changed the title [Bug] segmentation fault [Bug] segmentation fault on Intel HD Graphics 615 Hardware Oct 11, 2020
@sassman sassman changed the title [Bug] segmentation fault on Intel HD Graphics 615 Hardware [Bug] segmentation fault on Intel HD Graphics 615 Oct 11, 2020
@ghost
Copy link
Author

ghost commented Oct 11, 2020

Thank you for your researching, I also will look into.

can you check that iTerm for example is authorized with a checkbox there

ss

Right now, there is no checkbox for iTerm nor plus button to add iTerm. I believe this will show alert to permit when it requires (Maybe after segmentation fault is resolved...?)

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

Right now, there is no checkbox for iTerm nor plus button to add iTerm. I believe this will show alert to permit when it requires (Maybe after segmentation fault is resolved...?)

On start there should be a pop up coming that requests you to allow the recoding by iTerm

Additionally, I committed a fix to the main branch, that should do more checks and give more output.
Maybe you can

git clone https://github.com/sassman/t-rec-rs.git
cd t-rec-rs
cargo install -f --path .

and then redo a recording.

@ghost
Copy link
Author

ghost commented Oct 11, 2020

Thank you very much!
Oh, I'm afraid but is that fix commit not pushed yet...? (cloned and build, but it's same as before.)
https://github.com/sassman/t-rec-rs/commits/main

P.S.
I look into src/macos/window_id.rs, if anything works, I'll notify you

@ghost
Copy link
Author

ghost commented Oct 11, 2020

@sassman
It fixes.
I now am going to send you PR.

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

Oh, I'm afraid but is that fix commit not pushed yet...? (cloned and build, but it's same as before.)

Sorry pushed it as a wrong branch. Now you can try.

@ghost
Copy link
Author

ghost commented Oct 11, 2020

@sassman
Thank you very much.


It will take time (maybe not possible to fix from rust code side) to create PR, so I describe why this error caused.

First of all it was not because of graphic card.

The error was caused here.

    // src/macos/window_id.rs
    unsafe {
        CFRelease(window_list_info as CFTypeRef);
    }

Almost all application is fine with this, however, Übersicht does wrong.

ss 6

I think this is because of char code \u{308} does, because after I changed app name by editing info.plist of App, it works.

After I remove Übersicht and run correctly, this alert pops up.

Right now, there is no checkbox for iTerm nor plus button to add iTerm. I believe this will show alert to permit when it requires

Remarks

As I said, almost all of apps works correctly, even with Japanese-Named-Apps or Chinese-Named-Apps.
Only this, Combining Diacritical Marks breaks.

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

The umlaut "Ü" causes it. Very interesting. I will add some charset safety checks and also try to reproduce it. What app is it that is called "Übersicht" for you (maybe I can install it simply)?

@ghost
Copy link
Author

ghost commented Oct 11, 2020

Thank you for safety check proposal, I think it's a good idea.
This is the App.

Download: http://tracesof.net/uebersicht/
Github: https://github.com/felixhageloh/uebersicht

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

Download: http://tracesof.net/uebersicht/

Thanks, I can directly reproduce the issue now.

@ghost
Copy link
Author

ghost commented Oct 11, 2020

Additional Info (If this is an obvious thing, sorry. I really don't know anything about MacOS CoreFoundation).

If I modify the code below,

CGWindowListCopyWindowInfo(
kCGWindowListOptionIncludingWindow
| kCGWindowListOptionOnScreenOnly
| kCGWindowListExcludeDesktopElements,
kCGNullWindowID,

into below.

let window_list_info = unsafe {
    CGWindowListCopyWindowInfo(
            kCGWindowListOptionOnScreenOnly, kCGNullWindowID,
    )
};

Now, the error won't cause even with Übersicht. (OTOH, this makes functions TERM_PROGRAM="google chrome" t-rec disabled, so not right proposal. just additional info.)
ss 9


I think I am too lack of understanding CoreFoundation, so will stop my own PR... Thank you for reviewing my report. This is really good OSS.

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

Thanks for all the details, I found the reason. The Objective C runtime took over the memory ownership, of an item that it does not own. So that caused on the CFRelease somehow a double free that lead to the seg fault.

Can you please verify on the main branch if the problem is solved for you?

sassman added a commit that referenced this issue Oct 11, 2020
 - add more error checking and context to the lowlevel api calls
 - CFReleae caused a segmentation fault, related to a wrong treated memory onwership of a NSString variable
 - Add a bit safety for utf8 related issues on window name retrieval
@sassman sassman added this to the v0.1.1 milestone Oct 11, 2020
@sassman sassman self-assigned this Oct 11, 2020
@sassman
Copy link
Owner

sassman commented Oct 11, 2020

This fix is now included in v0.1.1 and published.

@sassman sassman changed the title [Bug] segmentation fault on Intel HD Graphics 615 [Bug] segmentation fault on listing the windows t-rec -l Oct 11, 2020
@sassman sassman closed this as completed Oct 11, 2020
@ghost
Copy link
Author

ghost commented Oct 11, 2020

@sassman
Yes, now it works with uebersicht!

Thank you very much for quick fix!

@sassman
Copy link
Owner

sassman commented Oct 11, 2020

@Ryuta69 thanks for your detailed feedback. The new version is just published on crates.io.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant