[vim/vim] xxd: buffer-overflow with specific flags (PR #14738)

28 views
Skip to first unread message

Lennard Hofmann

unread,
May 9, 2024, 12:15:41 PM5/9/24
to vim/vim, Subscribed

This is a continuation of #14003.

xxd writes each output line into a global buffer before printing. The maximum size of that buffer was not calculated correctly.

This command was crashing in AddressSanitizer:

xxd -Ralways -g1 -c256 -d -o 9223372036854775808 /etc/passwd

This prints a line of 6680 bytes but the buffer only had room for 6549 bytes. If the output from "-b" was colored, the line could be even longer.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/14738

Commit Summary

  • 5a9f59a xxd: buffer-overflow with specific flags

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738@github.com>

Christian Brabandt

unread,
May 9, 2024, 2:29:03 PM5/9/24
to vim/vim, Subscribed

thanks, can you please add a test for this? See https://github.com/vim/vim/blob/master/src/testdir/test_xxd.vim


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738/c2103199856@github.com>

Lennard Hofmann

unread,
May 9, 2024, 5:52:23 PM5/9/24
to vim/vim, Push

@Ordoviz pushed 1 commit.

  • 966494b xxd: buffer-overflow with specific flags


View it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738/push/18354850622@github.com>

Lennard Hofmann

unread,
May 9, 2024, 6:04:09 PM5/9/24
to vim/vim, Subscribed

@Ordoviz commented on this pull request.


In src/testdir/test_xxd.vim:

> @@ -411,6 +411,17 @@ func Test_xxd_max_cols()
   endfor
 endfunc
 
+
+" Try to trigger a buffer overflow (#14738)
+func Test_xxd_buffer_overflow()
+  new
+  let input = repeat('A', 256)
+  let expected = ' -9223372036854775808: ' . repeat("\e[1;32m41\e[0m ", 256) . ' ' . repeat("\e[1;32mA\e[0m", 256)

I don't know why the expected result starts with a space (it does not seem to be printed by xxd). I also think the offset shouldn't be negative but it is what it is.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738/review/2048910099@github.com>

Lennard Hofmann

unread,
May 9, 2024, 6:18:50 PM5/9/24
to vim/vim, Push

@Ordoviz pushed 1 commit.

  • 59baa82 Use tmp files to get rid of leading space


View it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738/push/18355088779@github.com>

K.Takata

unread,
May 9, 2024, 10:55:54 PM5/9/24
to vim/vim, Subscribed

@k-takata commented on this pull request.


In src/xxd/xxd.c:

> +    39             /* addr: ⌈log10(ULONG_MAX)⌉ if "-d" flag given. We assume ULONG_MAX = 2**128 */ \
+    + 2            /* ": " */ \
+    + 13 * COLS    /* hex dump with colors */ \
+    + (COLS - 1)   /* whitespace between groups if "-g1" option given and "-c" maxed out */ \
+    + 2            /* whitespace */ \
+    + 12 * COLS    /* ASCII dump with colors */ \
+    + 2            /* "\n\0" */
⬇️ Suggested change
-    39             /* addr: ⌈log10(ULONG_MAX)⌉ if "-d" flag given. We assume ULONG_MAX = 2**128 */ \
-    + 2            /* ": " */ \
-    + 13 * COLS    /* hex dump with colors */ \
-    + (COLS - 1)   /* whitespace between groups if "-g1" option given and "-c" maxed out */ \
-    + 2            /* whitespace */ \
-    + 12 * COLS    /* ASCII dump with colors */ \
-    + 2            /* "\n\0" */
+    (39            /* addr: ⌈log10(ULONG_MAX)⌉ if "-d" flag given. We assume ULONG_MAX = 2**128 */ \
+    + 2            /* ": " */ \
+    + 13 * COLS    /* hex dump with colors */ \
+    + (COLS - 1)   /* whitespace between groups if "-g1" option given and "-c" maxed out */ \
+    + 2            /* whitespace */ \
+    + 12 * COLS    /* ASCII dump with colors */ \
+    + 2)           /* "\n\0" */

It is better to surround with parentheses.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738/review/2049160171@github.com>

Lennard Hofmann

unread,
May 10, 2024, 3:42:51 AM5/10/24
to vim/vim, Push

@Ordoviz pushed 1 commit.

  • 224756c Add parentheses around C macro


View it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738/push/18359841502@github.com>

Christian Brabandt

unread,
May 10, 2024, 8:43:46 AM5/10/24
to vim/vim, Subscribed

Closed #14738 via 6779719.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/14738/issue_event/12769346248@github.com>

Reply all
Reply to author
Forward
0 new messages