woheller69/browser

crash in BannerBlock -- truncated file

Closed this issue · 3 comments

Managed to build and run your app in VS 2023.3.1.

It crashes on start-up. I debugged it, and the cause is pretty clear.

It reads the first 5k from
https://raw.githubusercontent.com/mozilla/cookie-banner-rules-list/main/cookie-banner-rules-list.json
but that file is more than 5k, so it gets truncated.

In loadHosts(), this causes a JSONException, which throws a RuntimeException.

First, rather than throwing the RuntimeException, I suggest that instead you Log the error.
The app continues to run without this facility.

Second, a fix to the problem would involve correcting the code that downloads the file
(NOT just increasing the buffer size.)

Cheers!@

I think this is rather an issue with your environment.
This download mechanism has been in place without any issues for many years. It is used in the same way for downloading
StevenBlack hosts.

It may be that something in the emulator environment cuts the transmission off, I can't say.
But this kind of problem could happen for any number of reasons.

The code response to it, of simply giving up and crashing, is a bad idea.

My suggestion, again, is to at least log the exception and continue.
For production code, it would be best to inform the user that the functionality will be unavailable, and explain why.

Cheers!

I made some adjustments:
13b8f41