Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index overflow access in Parser::parse_arguments() #9

Open
virtualritz opened this issue Apr 10, 2020 · 6 comments
Open

Index overflow access in Parser::parse_arguments() #9

virtualritz opened this issue Apr 10, 2020 · 6 comments

Comments

@virtualritz
Copy link

virtualritz commented Apr 10, 2020

This line will cause a crash when head equals lexeme.len():

stream.push(lexeme[head + 1].get_token_value()); //int f(int val)
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 3', src/library/parser/mod.rs:832:25
@virtualritz
Copy link
Author

Here is another one:

thread 'main' panicked at 'index out of bounds: the len is 178 but the index is 178', src/library/parser/mod.rs:432:27

@virtualritz
Copy link
Author

For reference, I am trying to transpile this file:
https://github.com/darktable-org/darktable/blob/master/src/iop/filmic.c

@guilhermedelyra
Copy link

Did you manage to find a workaround? I'm having the same issue

@virtualritz
Copy link
Author

Needs fixing. It was no important enough for me to bother ... I translated that source manually. :)

@Kubikx
Copy link

Kubikx commented Jul 15, 2020

:( I tried it too, and I have 5 files that can be easily merged to single one (~1.5 MB).
4 of the files have same problem. the last (smallest file only 188 kB) run for already 30 minutes using less than one CPU core and no log after the file size :(
I tried to return vec!["//TODO function :(".to_string()]; at the beginning of parse_function, where it fails next, and it printed:

Input file size : 1607527bytes
TokenizingInvoking Parser .... 564 : unop
 564 : unop
 564 : unop
 564 : unop
 564 : unop

and then nothing.
I was trying to print also lexeme: &Vec<Token> but I have no idea what it is, or what it should be, because the line numbers does not correspond to line numbers in the input file :(

There is no doc?, or did I just miss it, when I was looking to the repo?
I can not help if I have no idea why it is doing this. But generally lexeme[head + 1] seems like bad idea, especially when the loop condition is head < lexeme.len()

@YenForYang
Copy link

YenForYang commented May 19, 2021

I managed to "isolate" one of these errors. It happens for a basic function like this:

void blake2s_final( blake2s_state *S, byte *digest )
{
  for( int i = 0; i < 8; ++i )
    RawPut4( S->h[i], digest + 4 * i );
}

Strangely enough this particular case is solved by adding braces:

void blake2s_final( blake2s_state *S, byte *digest )
{
  for( int i = 0; i < 8; ++i ) {
    RawPut4( S->h[i], digest + 4 * i );
  }
}

I say this is strange because this would imply that for-loops require braces, but I've found cases where single line for-loops don't require braces.
It looks like I was wrong, for-loops seem to require braces.

Additionally, it looks like pre-processing directives for conditional compilation (#ifdef,#ifndef, etc.) causes the error as well. The use of headers also appears to mangle the output .rs file -- it probably has to do with the added commented code (since headers aren't supported).


If you're looking for test files, I recommend trying the source code of UnRAR from rarlab.com. All of the files I've tested in here (which doesn't mean all of them, just a lot of them) seem to give the index overflow error. The isolated example(s) above came from blake2s.cpp in the source code (it contains all the cases I mentioned that lead to the error). The version of source code I used is 6.0.5, but 6.0.6 works as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants