[Nasm-bugs] [Bug 3392726] New: incbin with empty string and -I switch, its length used in %rep, causes %rep error that hides other errors

noreply-nasm at dev.nasm.us noreply-nasm at dev.nasm.us
Mon Dec 14 08:02:03 PST 2020


https://bugzilla.nasm.us/show_bug.cgi?id=3392726

            Bug ID: 3392726
           Summary: incbin with empty string and -I switch, its length
                    used in %rep, causes %rep error that hides other
                    errors
           Product: NASM
           Version: 2.15.xx
          Hardware: All
                OS: All
            Status: OPEN
          Severity: minor
          Priority: Medium
         Component: Assembler
          Assignee: nobody at nasm.us
          Reporter: pushbx at ulukai.org
                CC: chang.seok.bae at intel.com, gorcunov at gmail.com,
                    hpa at zytor.com, nasm-bugs at nasm.us
     Obtained from: Built from git using configure

When passing the empty string to incbin I expect an error from incbin. However,
if the "length" of the incbinned data is used in a counter of a subsequent
%rep, and there is a valid -I switch with an existing directory on the NASM
command line, then the %rep will receive a very large value which will cause
NASM to fail with *that* error message. The problem is that the incbin error is
not displayed, making it difficult to figure out the cause of the error.

Here's a few test cases:

test$ nasm -v
NASM version 2.15.03rc1 compiled on Sep 30 2020
test$ cat test.asm
label:
incbin ""
%rep $ - label
%endrep
test$ nasm test.asm
test.asm:2: error: `incbin': unable to get length of file `'
test$ nasm test.asm -I ../lmacros/
test.asm:3: error: `%rep' count 9223372036854775807 exceeds limit (currently
1000000)
test$ cat test2.asm
incbin ""
test$ nasm test2.asm
test2.asm:1: error: `incbin': unable to get length of file `'
test$ nasm test2.asm -I ../lmacros/
test2.asm:1: error: `incbin': unexpected EOF while reading file `../lmacros/'
test2.asm:1: error: `incbin': error while reading file `../lmacros/'
test$ 


I came across this error during development of my FAT FS format script called
bootimg. If the generic def _PAYLOADFILE is not set on the NASM command line it
receives the default value of "" (the empty string, including quote marks).
Prior to the latest commit [1] this would lead to the incbin directive
receiving the empty string. An -I switch is generally needed for this script
because it needs the lmacros macro collection [2]. Finally, the size of the
incbin's data is used to determine the loop counter of a %rep [3] exposing this
NASM bug. As reported, the incbin error is not displayed by NASM in this case.
Likewise, the %error directive that is meant to notify the user about the
uninitialised def is also not displayed [4].


[1]: https://hg.ulukai.org/ecm/bootimg/rev/50b2a696666a
[2]: https://hg.ulukai.org/ecm/lmacros/
[3]: https://hg.ulukai.org/ecm/bootimg/file/50b2a696666a/bootimg.asm#l1298
[4]: https://hg.ulukai.org/ecm/bootimg/file/50b2a696666a/bootimg.asm#l243

-- 
You are receiving this mail because:
You are watching all bug changes.
You are on the CC list for the bug.


More information about the Nasm-bugs mailing list