! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Crashes when opening a UTF-8 encoded file that is exactly a multiple of memor...
Status:
RESOLVED: FIXED
Product:
Mousepad
Component:
General

Comments

Description Christopher Snowhill 2014-08-12 11:35:16 CEST
The following code, at line 521 of mousepad-file.c:

mapped_file = g_mapped_file_new (filename, FALSE, error);
contents = g_mapped_file_get_contents (mapped_file);

Eventually leads up to this at line 542:

         if (G_LIKELY (file->encoding == MOUSEPAD_ENCODING_UTF_8))
            {
              validate:

              /* glib uses a faster validator when the string is nul-terminated */
              if (G_LIKELY (length > 0 && contents[length] == '\0'))
                length = -1;

This code assumes that g_mapped_file_get_contents will always return NULL terminated. This may be the case when the contents are not exactly a multiple of pages in size and the last page has been wiped to zero before the file has been mapped into it. This is not the case when the file exactly meets a page boundary, in which case contents[length] is out of bounds and causes a crash.

This may be reproduced by creating a UTF-8 encoded text file which is exactly 4096 bytes in length, or 8192 bytes on a SPARC system, then attempting to open it.
Comment 1 Matthew Brush editbugs 2014-08-14 04:25:05 CEST
It should be fixed in http://git.xfce.org/apps/mousepad/commit/?id=959fe8b6266b74396d077fe90bc62aa1fd385c88. Do you mind testing? I wasn't (cap)able to reproduce the actual issue.
Comment 2 Christopher Snowhill 2014-08-14 13:12:17 CEST
I will forward this to the appropriate party to test. I have also edited the bug platform to FreeBSD / x86_64, which is the platform it affected for the user I reported on behalf of, rather than the platform that Bugzilla detected I was running.

When I have word that it works properly with that commented out, I will post back again.
Comment 3 Matthew Brush editbugs 2017-11-13 00:18:25 CET
*** Bug 13988 has been marked as a duplicate of this bug. ***

Bug #11079

Reported by:
Christopher Snowhill
Reported on: 2014-08-12
Last modified on: 2017-11-13
Duplicates (1):
  • 13988 Mousepad 0.3.0 Segfaults when opening a file 4096 bytes in size

People

Assignee:
Matthew Brush
CC List:
2 users

Version

Target Milestone:
Mousepad 0.2.x

Attachments

Additional information