#23475·radare2

r2: expanding a file size not working as expected

Author: afiskonCreated Oct 14, 2024Updated Apr 12, 2026

Environment

bash
eax@z930:~$ date
Mon Oct 14 15:00:03 MSK 2024

eax@z930:~$ r2 -v
radare2 5.9.7 32724 @ linux-x86-64
birth: git.5.9.6-5-g1cbab0f485 2024-10-14__14:39:51
commit: 1cbab0f48541e30a975154e953fb2fc9852263bb
options: gpl -O? cs:5 cl:2 make

eax@z930:~$ uname -ms
Linux x86_64

Description

I'm using r2 as a simple hex editor. While doing so I noticed that expending a binary file with r and checking the result with px shows that the file size was not affected. The w command doesn't seem to be aware of the additionally allocated space too. If I quit with q and open the same file again I see that the size was changed correctly. Truncating the file with r seems to work properly.

Test

echo aaa > test.bin

r2 -w test.bin

[0x00000000]> px 010
- offset -   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0123456789ABCDEF
0x00000000  6161 610a ffff ffff                      aaa.....
[0x00000000]> px 0x10
- offset -   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0123456789ABCDEF
0x00000000  6161 610a ffff ffff ffff ffff ffff ffff  aaa.............
[0x00000000]> r 0x10
[0x00000000]> r
16
[0x00000000]> px 0x10
- offset -   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0123456789ABCDEF
0x00000000  6161 610a ffff ffff ffff ffff ffff ffff  aaa.............
[0x00000000]> wx 11 22 33 44 55
[0x00000000]> px 0x10
- offset -   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0123456789ABCDEF
0x00000000  1122 3344 ffff ffff ffff ffff ffff ffff  ."3D............
[0x00000000]> q

r2 -w test.bin

[0x00000000]> px 0x10
- offset -   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0123456789ABCDEF
0x00000000  1122 3344 0000 0000 0000 0000 0000 0000  ."3D............