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

Crash in CosmeticFiltersJSHandler::OnHiddenClassIdSelectors #41728

Open
iefremov opened this issue Oct 18, 2024 · 2 comments · May be fixed by brave/brave-core#26123
Open

Crash in CosmeticFiltersJSHandler::OnHiddenClassIdSelectors #41728

iefremov opened this issue Oct 18, 2024 · 2 comments · May be fixed by brave/brave-core#26123
Assignees
Labels
crash priority/P2 A bad problem. We might uplift this to the next planned release.

Comments

@iefremov
Copy link
Contributor

iefremov commented Oct 18, 2024

https://share.backtrace.io/api/share/Snviyu4P8x1D5p1UWVPqIR2

[ 00 ] std::__Cr::vector<base::Value,std::__Cr::allocator<base::Value> >::size() ( vector:634 )
[ 01 ] base::Value::List::size() ( values.cc:985 )
[ 02 ] cosmetic_filters::CosmeticFiltersJSHandler::OnHiddenClassIdSelectors(base::Value::Dict) ( cosmetic_filters_js_handler.cc:703 )
[ 03 ] base::internal::DecayedFunctorTraits<void (cosmetic_filters::CosmeticFiltersJSHandler::*)(base::Value::Dict),cosmetic_filters::CosmeticFiltersJSHandler *>::Invoke((base::Value::Dict),cosmetic_filters::CosmeticFiltersJSHandler * &&,base::Value::Dict &&) ( bind_internal.h:738 )
[ 04 ] base::internal::InvokeHelper<0,base::internal::FunctorTraits<void (cosmetic_filters::CosmeticFiltersJSHandler::*&&)(base::Value::Dict),cosmetic_filters::CosmeticFiltersJSHandler *>,void,0>::MakeItSo((base::Value::Dict) &&,std::__Cr::tuple<base::internal::UnretainedWrapper<cosmetic_filters::CosmeticFiltersJSHandler,base::unretained_traits::MayNotDangle,0> > &&,base::Value::Dict &&) ( bind_internal.h:930 )
[ 05 ] base::internal::Invoker<base::internal::FunctorTraits<void (cosmetic_filters::CosmeticFiltersJSHandler::*&&)(base::Value::Dict),cosmetic_filters::CosmeticFiltersJSHandler *>,base::internal::BindState<1,1,0,void (cosmetic_filters::CosmeticFiltersJSHandler::*)(base::Value::Dict),base::internal::UnretainedWrapper<cosmetic_filters::CosmeticFiltersJSHandler,base::unretained_traits::MayNotDangle,0> >,void (base::Value::Dict)>::RunImpl((base::Value::Dict) &&,std::__Cr::tuple<base::internal::UnretainedWrapper<cosmetic_filters::CosmeticFiltersJSHandler,base::unretained_traits::MayNotDangle,0> > &&,std::__Cr::integer_sequence<unsigned long long,0>,base::Value::Dict &&) ( bind_internal.h:1067 )
[ 06 ] base::internal::Invoker<base::internal::FunctorTraits<void (cosmetic_filters::CosmeticFiltersJSHandler::*&&)(base::Value::Dict),cosmetic_filters::CosmeticFiltersJSHandler *>,base::internal::BindState<1,1,0,void (cosmetic_filters::CosmeticFiltersJSHandler::*)(base::Value::Dict),base::internal::UnretainedWrapper<cosmetic_filters::CosmeticFiltersJSHandler,base::unretained_traits::MayNotDangle,0> >,void (base::Value::Dict)>::RunOnce(base::internal::BindStateBase *,base::Value::Dict &&) ( bind_internal.h:980 )
[ 07 ] base::OnceCallback<void (base::Value::Dict)>::Run(base::Value::Dict) ( callback.h:157 )
[ 08 ] cosmetic_filters::mojom::CosmeticFiltersResources_HiddenClassIdSelectors_ForwardToCallback::Accept(mojo::Message *) ( cosmetic_filters.mojom.cc:451 )
[ 09 ] mojo::InterfaceEndpointClient::HandleValidatedMessage(mojo::Message *) ( interface_endpoint_client.cc:1021 )

@iefremov iefremov added crash priority/P2 A bad problem. We might uplift this to the next planned release. labels Oct 18, 2024
@atuchin-m
Copy link
Contributor

Looks like it's not okay to return Dict() here and in the similar places if we (D)CHECKing some fields:
https://github.com/brave/brave-core/blob/master/components/cosmetic_filters/renderer/cosmetic_filters_js_handler.cc#L655

@atuchin-m
Copy link
Contributor

atuchin-m commented Oct 21, 2024

According to @iefremov logs on https://imageresizer.com/ with some extra filter lists we got the following call:
cf_worker.hiddenClassIdSelectors(JSON.stringify({"classes":["max-md:bottom-[156px]","max-lg:bottom-[196px]","h-screen","border-b-irGray-200","z-30","min-h-0","overflow-x-auto","overflow-y-hidden","border-r-irGray-200","dark:border-r-darkSurface-600","scroll","px-1","bg-slate-200","hover:bg-slate-200","focus:outline","focus:outline-irBlue-400","dark:focus:outline-none","overflow-y-auto","max-h-full","pt-6","lg:text-2xl","lg:gap-8","pb-8","lg:pb-0","py-1","dark:bg-darkSurface-400","text-irGray-600","items-end","pb-2","border-irGray-400","dark:border-darkSurface-100","select-all","mt-1","mt-2","border-slate-400","bg-blue","dark:bg-darkPrimary-200","lg:pb-24","pt-2","rounded-r-none","border-r-0","bg-transparent","p-1","my-react-select-container","css-b62m3t-container","css-7pg0cj-a11yText","my-react-select__control","css-13cymwt-control","my-react-select__value-container","my-react-select__value-container--has-value","css-hlgwow","my-react-select__single-value","css-1dimb5e-singleValue","my-react-select__input-container","css-19bb58m","my-react-select__input","my-react-select__indicators","css-1wy0on6","my-react-select__indicator-separator","css-1u9des2-indicatorSeparator","my-react-select__indicator","my-react-select__dropdown-indicator","css-1xc3v61-indicatorContainer","css-8mmkcg","py-3","pointer-events-none","z-0","border-t-irGray-200","block","cursor-not-allowed","text-2xl","min-w-728-pc","gap-2.5","py-[5px]","text-xs","dark:bg-darkSurface-300","py-0.5","z-20","items-stretch","h-2/3","lg:h-full","items-start","top-full","outline","outline-irBlue-200","dark:outline-darkPrimary-100","font-normal","pointer-events-auto","lg:my-auto","inset-x-0","grid-cols-3"],"ids":["max-file-size-unit","react-select-4-live-region","react-select-4-input","resize-settings-save-as","react-select-5-live-region","react-select-5-input","placeholder","\udc75","\udc7e"]}))

It resulted in DCHECK/crash for the reason I mentioned above.

Removing the last ,"\udc75","\udc7e" fixes the issue.

IMHO, we shouldn't parse classes and ids on C++ side. Instead, we'd better replace HiddenClassIdSelectors( const std::string& input) to HiddenClassIdSelectors( const std::string class_list, const std::string& id_list) and parse them in Rust to avoid workarounds like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash priority/P2 A bad problem. We might uplift this to the next planned release.
Projects
Status: To do
Development

Successfully merging a pull request may close this issue.

3 participants