radareorg / radare2-r2pipe

Access radare2 via pipe from any programming language!
390 stars 99 forks source link

Treat running out of bytes the same as a failed match, like takeWhile in base does, instead of crashing #157

Closed josephcsible closed 1 year ago

josephcsible commented 1 year ago

Checklist

Description

See the Stack Overflow question Different behavior in GHCI and GHC (Running radare2 pipe) for context. When the real takeWhile runs out of elements, it stops gracefully the same as if it found an element that didn't match its predicate. This change makes us do the same thing, instead of crashing.

trufae commented 1 year ago

Merged! Thank you!

tomhepworth commented 1 year ago

I get strange behaviour now. Sometimes when I use stack run I get the correct result, sometimes I get the error ...-exe: fd:56: hFlush: resource vanished (Broken pipe)

I am unsure if this is related

josephcsible commented 1 year ago

The underlying cause of both the Data.ByteString.Lazy.head: empty ByteString error and your new error appear to be the same, namely that radare2 is exiting when your pipe code expects it to still be running. So it's not that this change caused that problem, but rather it fixed an earlier crash that allowed the second to become visible.

trufae commented 1 year ago

Uhm. Is r2 crashing?

tomhepworth commented 1 year ago

I assume it must be, it only seems to happen when I call it through the Haskell r2-pipe code in a compiled binary. It does not happen if I call main from the Haskell interpreter. My original stack overflow question was essentially "How come it's different through ghc compared to ghci", so perhaps there is some quirk I don't understand with how Haskell runs processes

trufae commented 1 year ago

Is this latest r2 from git? Do you have a backtrace/crashlog/reproducer? Maybe you can attach a debugger before the crash happens.

Afaik you are spawning r2 from haskell and then using pipes right?