diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp index 31c8c4402ac149602df488e52a07c38f8876fa2a..6d13dc88e4680fdf1f519f79c05367e646e0cf5d 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,6 +35,10 @@ void TimeStatistician::CalAverFeedInterval(const int64_t feedTime) return; } feedIndex_++; + if (feedIntervalSum_ > INT64_MAX - feedInterval_) { + DHLOGE("feedIntervalSum_ overflow"); + return; + } feedIntervalSum_ += feedInterval_; averFeedInterval_ = feedIntervalSum_ / static_cast(feedIndex_); lastFeedTime_ = feedTime_; @@ -49,6 +53,10 @@ void TimeStatistician::CalAverTimeStampInterval(const int64_t timeStamp) return; } timeStampIndex_++; + if (timeStampIntervalSum_ > INT64_MAX - timeStampInterval_) { + DHLOGE("timeStampIntervalSum_ overflow"); + return; + } timeStampIntervalSum_ += timeStampInterval_; averTimeStampInterval_ = timeStampIntervalSum_ / static_cast(timeStampIndex_); lastTimeStamp_ = timeStamp_; diff --git a/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp b/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp index 98d6b0a5c15526ee9071115b094021eff86ac653..d2c7c0d37f3c7e381847bf6c7cf081a02c6806df 100644 --- a/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp +++ b/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -143,6 +143,10 @@ void FpsControllerProcess::UpdateFrameRateCorrectionFactor(int64_t nowMs) const float msPerSecond = 1000; const float maxInstantaneousFrameRateCoefficient = 1.1; float maxInstantaneousFrameRateThreshold = targetFrameRate_ * maxInstantaneousFrameRateCoefficient; + if (recentFrameTimeSpanMs_ == 0) { + DHLOGE("Frame control, recentFrameTimeSpanMs_ is 0, cannot calculate frame rate."); + return; + } float instantaneousFrameRate = msPerSecond / recentFrameTimeSpanMs_; if (instantaneousFrameRate < 0) { instantaneousFrameRate = -instantaneousFrameRate; @@ -275,6 +279,10 @@ bool FpsControllerProcess::ReduceFrameRateByUniformStrategy(int32_t incomingFrmR * rate, the incoming frames are reduced uniformly. */ bool isDrop = false; + if (frameRateOvershootMdf_ > INT32_MAX - (incomingFrmRate - targetFrameRate_)) { + DHLOGE("Overshoot value is too large, reset to 0."); + return false; + } int32_t overshoot = frameRateOvershootMdf_ + (incomingFrmRate - targetFrameRate_); if (overshoot < 0) { overshoot = 0;