mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-24 11:22:44 +01:00
Reject downloaded lists which are deemed truncated
Related feedback: - https://www.reddit.com/r/uBlockOrigin/comments/hbpo86/ For unknown reasons at this point, it appears some users end up with a truncated version of EasyList, leading to improper blocking in uBO. This commit adds a heuristic to discard a downloaded list when its new size is more than 25% smaller than the currently cached version.
This commit is contained in:
parent
774fb15ebb
commit
de219dae26
@ -771,6 +771,22 @@ const getRemote = async function(assetKey) {
|
|||||||
? await api.fetchFilterList(contentURL)
|
? await api.fetchFilterList(contentURL)
|
||||||
: await api.fetchText(contentURL);
|
: await api.fetchText(contentURL);
|
||||||
|
|
||||||
|
// https://www.reddit.com/r/uBlockOrigin/comments/hbpo86/
|
||||||
|
// Server sent a truncated list? If the new list is smaller than the
|
||||||
|
// currently cached one by more than 25%, assume a server error.
|
||||||
|
if (
|
||||||
|
stringIsNotEmpty(result.content) &&
|
||||||
|
typeof assetDetails.size === 'number' &&
|
||||||
|
assetDetails.size !== 0
|
||||||
|
) {
|
||||||
|
const loss = 1 - result.content.length / assetDetails.size;
|
||||||
|
if ( loss > 0.25 ) {
|
||||||
|
result.statusCode = 206;
|
||||||
|
result.statusText = 'Partial Content';
|
||||||
|
result.content = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Failure
|
// Failure
|
||||||
if ( stringIsNotEmpty(result.content) === false ) {
|
if ( stringIsNotEmpty(result.content) === false ) {
|
||||||
let error = result.statusText;
|
let error = result.statusText;
|
||||||
@ -788,7 +804,10 @@ const getRemote = async function(assetKey) {
|
|||||||
content: result.content,
|
content: result.content,
|
||||||
url: contentURL
|
url: contentURL
|
||||||
});
|
});
|
||||||
registerAssetSource(assetKey, { error: undefined });
|
registerAssetSource(assetKey, {
|
||||||
|
error: undefined,
|
||||||
|
size: result.content.length
|
||||||
|
});
|
||||||
return reportBack(result.content);
|
return reportBack(result.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user