DIGImend / hidrd

HID report descriptor I/O library and conversion tool
GNU General Public License v2.0
171 stars 29 forks source link

Can't parse a hid-dump - invalid item encountered #18

Open Duckbuster opened 7 years ago

Duckbuster commented 7 years ago

I'm trying to convert a hid-dump with hidrd-convert. but it says invalid item encountered. this is what I am trying to do:

cat nano_hid_dump | grep -v : | xxd -r -p | hidrd-convert -o spec > nano_spec
Failed to read input item at offset 728:
invalid item encountered

The hid_dump in question I have uploaded here: https://a.lolisandstuff.moe/pbuwfny

tmk commented 7 years ago

This online parser shows your dump includes three invalid bytes at end of file. http://eleccelerator.com/usbdescreqparser/

With removing those bytes from the dump the command works well. This is not a bug but it would be useful if we can get halfway converted output even when error occurs.

EDIT: I'm not sure if this is safe but I could get output anyhoo.

diff --git a/src/hidrd-convert.c b/src/hidrd-convert.c
index 8945217..564336c 100644
--- a/src/hidrd-convert.c
+++ b/src/hidrd-convert.c
@@ -351,7 +351,7 @@ process(const char *input_name,
         fprintf(stderr, "Failed to read input item at %s:\n%s\n",
                 (posstr = hidrd_src_fmtpos(input, pos)),
                 (err = hidrd_src_errmsg(input)));
-        goto cleanup;
+        //goto cleanup;
     }

     /*
spbnick commented 7 years ago

Thank you, @Duckbuster, @tmk, I agree it would be good to handle invalid bytes. I think the right way would be to preserve and output them as such, i.e. invalid bytes. I only need to find time to implement that.

S4mw1s3 commented 7 years ago

Those invalid bytes can be preserved, but I think a warning should also be shown that there were invalid bytes because thanks to the error that is shown now, we found out that there was an issue in usbhid-dump.

I'm a colleague of @Duckbuster and I started investigating why we got these invalid bytes in the first place. We found that we needed this fix in usbhid-dump (https://github.com/DIGImend/usbhid-dump/commit/cc74aae8d020e0ddd069dbb107900cec54e56cd5). If the error was not shown in hidrd-convert and the invalid bytes were silently preserved, I would have ended up with an invalid hid descriptor...

The fix is already old but it didn't end up in the usbhid-dump version in our distro because no release of usbutils was made since that fix. I asked for a new release of usbutils (https://github.com/gregkh/usbutils/issues/57) and in the mean time I'll use a version of usbhid-dump which I compiled myself.

Thanks for the good work!

spbnick commented 7 years ago

Thank you, that's good to hear. Let's leave this issue open, though, as there are more broken devices out there.

S4mw1s3 commented 7 years ago

FYI, Just found out now but this one is more or less a duplicate of https://github.com/DIGImend/hidrd/issues/11 .