malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.25k stars 31 forks source link

Yedit 20201110 - Crash with backspace #66

Closed Gavin-Holt closed 3 years ago

Gavin-Holt commented 4 years ago

Hi

I am using Yedit more and more, I love the simplicity.

However, there is something triggering a full crash after backspace and unfortunately it's not fully consistent:

I suspect that saving the file has some effect but I cannot pin point what.

Hope this is enough to track down the problem.

Kind Regards Gavin Holt

Gavin-Holt commented 3 years ago

This seems to have disappeared with yedit 20201129.

Many thanks G

malxau commented 3 years ago

Which version had the problem? There were a lot of changes and fixes to yedit before 1.40, but nothing since then, so if the latest build works and 1.40 has the problem, the problem is probably still there. Were you running the debug build?

I tried to repro this in various cases that I could think of but wasn't successful, which is why I hadn't commented here about it.

Note that debug builds change page protections on free so they crash on use-after-free, and try to align allocations to the end of a page so they crash on buffer overrun. Unfortunately yedit partially circumvents this for performance, because it loads a whole file into large memory allocations and the lines are all just pointing back into that single memory allocation, so it's very hard to free or overrun that allocation. However, if you join two lines together by deleting a line break, it requires a new allocation for the line because the combined text won't fit in the old allocation, which enables this type of memory bug detection to start working again.

If you have seen this bug on 1.40, I think the next step is for me to read the code carefully and see if I can find a condition that might not handle memory correctly.