From 806414df4370e669f01a1679f1b53e048b905379 Mon Sep 17 00:00:00 2001 From: Renzo <170978465+RenzoMXD@users.noreply.github.com> Date: Tue, 26 May 2026 09:51:05 +0700 Subject: [PATCH] Go: validate Baidu OCR inputs (#15168) ### What problem does this PR solve? Closes #15167. The Baidu Go provider advertises OCR support through `paddleocr-vl-0.9b`, but `BaiduModel.OCRFile` dereferenced required inputs before validating them. Calling OCR with a missing API config, API key, or model name could panic instead of returning a normal error. This PR adds explicit input validation for those required values. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: Jin Hai --- internal/entity/models/baidu.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/entity/models/baidu.go b/internal/entity/models/baidu.go index daa0b763a7..4897c3db4c 100644 --- a/internal/entity/models/baidu.go +++ b/internal/entity/models/baidu.go @@ -638,6 +638,12 @@ func (b *BaiduModel) OCRFile(modelName *string, content []byte, fileURL *string, if (fileURL == nil || *fileURL == "") && (content == nil || len(content) == 0) { return nil, fmt.Errorf("image url or content is required") } + if apiConfig == nil || apiConfig.ApiKey == nil || *apiConfig.ApiKey == "" { + return nil, fmt.Errorf("api key is required") + } + if modelName == nil || *modelName == "" { + return nil, fmt.Errorf("model name is required") + } region := "default" if apiConfig.Region != nil && *apiConfig.Region != "" {