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
Web UI sometimes fails to display trace for MT issues #4
Comments
@0xedward I debugged this for some time and it appears as though the issue is with the db provided (spurious information, either the db or the files have been changed after running MT) or an issue with MT itself. What I did was tried to log issues which passes the line number to various functions till it reaches the source where we try to access the line number th line. For instance, one of the issues I logged is:
As you can see the issue location is at line number 35, from 0th place char to the 1st (in sense of an array of chars) package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
/* loaded from: classes2.dex */
public class MainActivity extends AppCompatActivity {
/* access modifiers changed from: protected */
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
setContentView(2131427356);
((Button) findViewById(2131230792)).setOnClickListener(new View.OnClickListener() { // from class: com.example.myapplication.MainActivity.1
@Override // android.view.View.OnClickListener
public void onClick(View v) {
CodeExecuteUtil.execute(intent.getStringExtra("command"));
}
});
if (intent.getBooleanExtra("redirect", false)) {
Intent redirectIntent = new Intent();
redirectIntent.setData(intent.getData());
startActivity(redirectIntent);
}
}
} This lead me to the above conclusion. I couldn't ascertain which of the above this be the result of, but if you want, I could prevent this error from happening by pointing to the last line if in case such a catastrophe happens. |
@abishekvashok - oh, interesting! Does this issue you mention reproduce if you do the following?
|
@0xedward so I did some digging up and the findings affirm my conclusion. This is if the source code provided, I assume, is same as the sample app in the repository. Otherwise I would also need the apk to run MT. So if it is same as the sample app, all is well. Every issue has traces displayed without errors. eg) the 2nd one: |
@0xedward compiled the apk as suggested. No issues on running the newly created project with the source provided: But however, the error is reproducible when sapp has invested the results and when file has changed. Do you want to anchor this issue to implement the "snapshot" behaviour you guys have internally? If so, I was curious to know which method you would prefer: create a pipeline step to add the files which are associated with traces to the db on a snapshots table, make freezable copies of the file and save them as archives associated with run ids, or something entirely else :) |
@abishekvashok thanks for spending the time to find the root cause of this! It looks like our guess was right :)
My initial thoughts are that it makes sense for us to mirror what we have internally, but I have a few concerns so I'll message a few people to see if I can sort out (e.g. SAPP is a dependency for some internal projects, UI for making it clear to our users that they are viewing a snapshot of their code, what do we do if the user doesn't specify
Depending on how the internal discussions go, my guess here is creating pipeline step to snapshot files when the user runs |
@0xedward digged in deeper with suggestions following the meeting (thanks for them). We indeed have commit hash relating with each run which leads me to believe we could use it in the file connection response to the UI and if there isn't a commit hash associated with the run, either:
My only concern for the second option is the creation of duplicate snapshots when the run is imported again and again and the inability of us to add another third party library to sapp because you guys have to support it internally. |
Summary: Prevent sapp frontend from crashing if there if a source file contains less number of lines that expected. Pull Request resolved: #58 Test Plan: - run pysa/Mariana Trench parser and import the results to sapp - make sure you have source code. Modify the source code to make the taint location invalid - run sapp `python3 -m sapp.cli server --debug --source-directory <source-directory>` - start the frontend, `cd sapp/ui/frontend && npm run-script start` - goto https://localhost:3000 and click on an issue. - See sapp showing the new error message and not crashing. Signed-off-by: Abishek V Ashok <abishekvashok@gmail.com> Fixes: MLH-Fellowship#4 Reviewed By: dkgi Differential Revision: D31994810 Pulled By: 0xedward fbshipit-source-id: 9b33ca885407a42997c39c2ce9ef73594007a5d1
Closed via facebook@01df95d |
Hi @0xedward and @abishekvashok I don't think this is fully fixed yet I'm still experiencing the same issue using |
@BitTheByte that's very unfortunate. Do you mind giving more details? Like a screenshot of the things in the console for example... we did try to check a possible few cases before closing this and would help if you could give more of a context as to when this happens. Also thanks for trying this out - really appreciate it :) |
Hey @BitTheByte, thanks for looking into this after the latest release! :) Like @abishekvashok mentioned, would you be able to provide rough steps to reproduce for the issue you are still running into? Only if it's possible and you're comfortable with sharing, it would be really helpful if you could share your |
Hi @abishekvashok and @0xedward $ sapp --database-name=sapp.db server --source-directory=src/main/java
Find the apk, decompiled sources, and Below is the message shown at the browser console. and a small snippet of the code causing the error
function adjustRange(range: Range, lines: $ReadOnlyArray<string>): Range {
// TODO(T78595608): workaround for inaccurate Pysa locations with leading and
// trailing whitespaces.
// Assuming all ranges are single line.
const source = lines[range.from.line].slice(range.from.ch, range.to.ch); // << ERROR
const leadingWhitespace = source.search(/\S/);
const trailingWhitespace = source.length - source.trimEnd().length;
return {
from: {
line: range.from.line,
ch: range.from.ch + leadingWhitespace,
},
to: {
line: range.to.line,
ch: range.to.ch - trailingWhitespace,
},
};
} Note that I'm using Thanks for taking the time fixing and looking into this issue :) |
@BitTheByte thank you for this @0xedward I took a look and it seems MT is reporting line numbers in an off by one fashion.While I think pysa has line numbers starting from 1, MT (maybe for this db) has for some issues 0, as line numbers. const source = lines[range.from.line].slice(range.from.ch, range.to.ch); // << ERROR I think we can fix this by modifying the MT parser pipeline step in to line = position.get("line", UNKNOWN_LINE)
if line != UNKNOWN_LINE:
line = line + 1 or modifying UNKNOWN_LINE to |
Steps to Reproduce:
Download the zip of a SAPP db containing the MT run to help you reproduce the issue and the source code of what MT was run on
Extract both zip files and run the following command to get started looking into this in SAPP
2
in Run1
Here are the relevant local vars when the exception is thrown:
lines
:range
:As a starting point, this issue likely occurs because of a off-by-one error when referencing
lines
in https://github.com/facebook/sapp/blob/main/sapp/ui/frontend/src/Source.js#L40Submitting a PR
We use the following linters internally, so to save everyone's time, please make sure you run the following linters locally and fix errors related to the files you modified before submitting a PR:
To install the linters, you can run the following command:
The text was updated successfully, but these errors were encountered: