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

Alt+Backspace off-by-one and segfault (UTF-8) #256

Closed
mc-butler opened this issue Feb 5, 2009 · 37 comments
Closed

Alt+Backspace off-by-one and segfault (UTF-8) #256

mc-butler opened this issue Feb 5, 2009 · 37 comments
Labels
area: core Issues not related to a specific subsystem prio: high Serious problem that could block progress ver: 4.7.0-pre4 Reproducible in version 4.7.0-pre4
Milestone

Comments

@mc-butler
Copy link

Important

This issue was migrated from Trac:

Origin https://midnight-commander.org/ticket/256
Reporter egmont (@egmontkob)
Mentions dborca@….com, egmont@….com (@egmontkob)

The UTF-8 patch introduces this regression: Ctrl+Left and Alt+Backspace proceed one more character than they should.

(Consistently with unpatched mc, bash, and probably lots of other tools, Alt+Backspace should remove a sequence of non-alphanumeric characters followed by a sequence of alphanumeric ones, but instead it removes one more non-alphanumeric character at the end. Similar for Ctrl+Left.)

Trivial patch is attached. I've created this patch years ago and posted to mc-devel; probably it's already included in some major Linux distributions as well.

Please apply this fix in your UTF-8 patch. Thanks!

Note

Original attachments:

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Feb 5, 2009 at 22:24 UTC

Fix for the bug.

@mc-butler
Copy link
Author

Changed by winnie (@winnieXY) on Mar 9, 2009 at 9:59 UTC (comment 1)

  • Status changed from new to accepted
  • Owner set to winnie
  • Milestone changed from 4.6.2.1 to UTF8 Support

The same applies here. This is no bug for the 4.6.2.1 release...

@mc-butler
Copy link
Author

Changed by winnie (@winnieXY) on Mar 16, 2009 at 15:21 UTC (comment 2)

  • Resolution set to fixed
  • Status changed from accepted to testing

Patch is applied to both HACK_utf8 branches and will be included in the next release

@mc-butler
Copy link
Author

Changed by winnie (@winnieXY) on Mar 16, 2009 at 15:26 UTC (comment 3)

  • Status changed from testing to closed

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Jun 26, 2009 at 15:19 UTC (comment 4)

  • Milestone UTF8 Support deleted
  • Resolution fixed deleted
  • Status changed from closed to reopened

need check it

@mc-butler
Copy link
Author

Changed by styx (@styx) on Jul 30, 2009 at 13:07 UTC (comment 5)

  • Milestone set to future releases
  • Severity set to no branch

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Jul 30, 2009 at 17:42 UTC (comment 6)

  • Resolution set to fixed
  • Status changed from reopened to closed

now all correct

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Jul 30, 2009 at 17:50 UTC (comment 7)

  • Milestone changed from future releases to 4.7

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 19, 2009 at 22:05 UTC (comment 8)

  • Cc set to egmont@….com
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 4.6.2 to 4.7.0-pre2

Reopening: same bug is present in 4.7-pre2. Probably it was fixed in the 4.6 branch, but not in the complete UTF-8 rewrite for 4.7.

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 19, 2009 at 22:43 UTC (comment 9)

Patch attached, please test it thoroughly. (It's slightly different than the one used for 4.6. As a matter of fact, I don't fully understand how that one worked correctly :))

The trick is: p points to the location of the cursor, that is, the first byte of the character it stands under. When moving forward, you have to examine this character and see if it's alphanumerical or not - easy story. When moving backwards, however, you need to check the preceding character, not this one.

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 19, 2009 at 22:43 UTC

Fix for off-by-one error in mc 4.7-pre2.

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Sep 20, 2009 at 10:55 UTC (comment 10)

  • Owner changed from winnie to angel_il
  • Status changed from reopened to accepted
  • Milestone changed from 4.7 to 4.7.0-pre3

@mc-butler
Copy link
Author

Changed by iNode (@iNode) on Sep 20, 2009 at 15:27 UTC (comment 11)

#1481 seems to be related or the same bug.

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Sep 20, 2009 at 18:40 UTC (comment 12)

Yep, exactly the same bug.

@mc-butler
Copy link
Author

Changed by iNode (@iNode) on Sep 22, 2009 at 10:55 UTC (comment 13)

  • Milestone 4.7.0-pre3 deleted
  • Blocking #1481 deleted
  • Resolution set to duplicate
  • Status changed from accepted to testing
  • Version 4.7.0-pre2 deleted

Ok, I close this as duplicate to cleanup roadmap.

@mc-butler
Copy link
Author

Changed by slavazanko (@slavaz) on Oct 7, 2009 at 9:09 UTC (comment 14)

  • Status changed from testing to reopened
  • Cc changed from egmont@….com to dborca@….com, egmont@….com
  • Resolution duplicate deleted

#1481 is closed as duplicate.

WARNING: #1481 contain some patch.

@mc-butler
Copy link
Author

Changed by slavazanko (@slavaz) on Oct 7, 2009 at 9:10 UTC (comment 15)

  • Status changed from reopened to assigned

@mc-butler
Copy link
Author

Changed by slavazanko (@slavaz) on Oct 7, 2009 at 9:15 UTC (comment 16)

  • Milestone set to 4.7.0-pre4
  • Version set to 4.6.1

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Oct 7, 2009 at 9:30 UTC (comment 17)

  • Votes set to angel_il
  • Severity changed from no branch to on review

branch: 256_widget_backward_kill_word_fix (parent: master)
changeset: [a9c0acc89560548a8df3ca9d0fb4d24b47022434]

@mc-butler
Copy link
Author

Changed by slavazanko (@slavaz) on Oct 7, 2009 at 10:43 UTC (comment 18)

  • Votes angel_il deleted

See my last [016d79cdceb60faddfb6d798138753efe6d2f96d]

@mc-butler
Copy link
Author

Changed by slavazanko (@slavaz) on Oct 7, 2009 at 10:47 UTC (comment 19)

Ops, I forgot to remove some code: [a12abcf77a94f1bd4bf71b2ef3990d5fa6d4be06]
Need rebase

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Oct 7, 2009 at 10:53 UTC (comment 20)

  • Votes set to angel_il

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Oct 7, 2009 at 12:20 UTC (comment 21)

  • Votes changed from angel_il to angel_il andrew_b
  • Severity changed from on review to approved

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Oct 7, 2009 at 13:25 UTC (comment 22)

  • Votes changed from angel_il andrew_b to commited-master
  • Status changed from assigned to testing
  • Severity changed from approved to merged
  • Resolution set to fixed

Fixed: [9bec191]

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Oct 7, 2009 at 13:26 UTC (comment 23)

  • Status changed from testing to closed

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Nov 4, 2009 at 12:44 UTC (comment 24)

  • Resolution fixed deleted
  • Milestone changed from 4.7.0-pre4 to 4.7.0
  • Version changed from 4.6.1 to 4.7.0-pre4
  • Status changed from closed to reopened
  • Priority changed from minor to critical

Reopening. Unfortunately still not fixed, and the new behavior might even cause segfault, hence is much more harmful than the old one.

If you type English letters only (e.g. "patch.gz") then Alt+Backspace works as expected, it removes "gz" first, then removes "patch.", then does nothing.

The bug happens when you start using accented letters. Type "áá.éé" for example, and then press Alt+Backspace. It removes ".éé" - already buggy. Press it once again, seems to do nothing. Press once or twice again, still seems to do nothing.

Then start typing normal letters. The first few ones don't appear, but then suddenly they start appearing. If you keep on doing various things in mc, you'll pretty soon get a segmentation fault.

Definitely looks like a buffer underrun.

I can't tell at this moment if my originally propsed patch was already buggy or not. I will take a closer look and try to come up with a fix later, I don't have time right now.

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Nov 4, 2009 at 19:37 UTC (comment 25)

My previously proposed w/ 4.7-pre2 is already broken. Sorry for that. Working on the fix...

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Nov 4, 2009 at 19:52 UTC

fix for segfault and other weird errors

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Nov 4, 2009 at 19:59 UTC (comment 26)

Fix attached.

The for loop, whose purpose is to remove exactly 1 character (hence I don't get why it's a loop, but nevermind) was not UTF8-ready. So if the character preceding the cursor was an accented one, it jumped to the middle of the UTF-8 sequence, causing the rest of the stuff go unpredictable.

Although it *should* never happen (which, as we all know, does not equal to "never happens"), in this case "p" simply jumped over "in->buffer". The function has a "p != in->buffer" check three times, it might it more robust if you replaced that with "p >= in->buffer". This should prevent the segfault, and just stay with a slightly buggy but otherwise harmless alt-backspace behavior, should there be any UTF-8 or similar bugs left. This change is not included in my patch.

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Nov 5, 2009 at 5:10 UTC (comment 27)

  • Votes commited-master deleted
  • Severity changed from merged to no branch

@mc-butler
Copy link
Author

Changed by zaytsev (@zyv) on Nov 9, 2009 at 18:07 UTC (comment 28)

Use assert() to catch this?

@mc-butler
Copy link
Author

Changed by egmont (@egmontkob) on Nov 14, 2009 at 19:46 UTC (comment 29)

  • Summary changed from Alt+Backspace off-by-one (UTF-8) to Alt+Backspace off-by-one and segfault (UTF-8)

=, assert, whatever... up to you :)

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Nov 18, 2009 at 8:45 UTC (comment 30)

  • Votes set to angel_il
  • Severity changed from no branch to on review

branch: 256_backward_word_fix
changeset: [ecee0cd]

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Nov 18, 2009 at 8:56 UTC (comment 31)

  • Votes changed from angel_il to angel_il andrew_b
  • Severity changed from on review to approved

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Nov 18, 2009 at 9:37 UTC (comment 32)

  • Status changed from reopened to closed
  • Severity changed from approved to merged
  • Votes angel_il andrew_b deleted
  • Resolution set to fixed

Fixed: [7e30a30]

@mc-butler
Copy link
Author

Changed by angel_il (@ilia-maslakov) on Nov 18, 2009 at 22:26 UTC (comment 33)

  • Votes set to committed-master

@mc-butler
Copy link
Author

Changed by zaytsev (@zyv) on Feb 20, 2025 at 15:55 UTC (comment 34)

Ticket #1481 has been marked as a duplicate of this ticket.

@mc-butler mc-butler marked this as a duplicate of #1481 Feb 28, 2025
@mc-butler mc-butler marked this as a duplicate of #1672 Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues not related to a specific subsystem prio: high Serious problem that could block progress ver: 4.7.0-pre4 Reproducible in version 4.7.0-pre4
Development

No branches or pull requests

1 participant