Merge pull request #148 from cogwheel0/feat-improve-base64-image-parsing

feat(file-attachment): improve base64 image data URL parsing validation
This commit is contained in:
cogwheel
2025-11-13 12:39:29 +05:30
committed by GitHub

View File

@@ -180,8 +180,21 @@ class FileAttachmentService {
int? maxHeight, int? maxHeight,
) async { ) async {
try { try {
// Decode base64 data // Decode base64 data - with validation
final data = imageDataUrl.split(',')[1]; final parts = imageDataUrl.split(',');
if (parts.length < 2) {
DebugLogger.log(
'Invalid data URL format - missing comma separator',
scope: 'attachments/image',
data: {
'urlPrefix': imageDataUrl.length > 50
? imageDataUrl.substring(0, 50)
: imageDataUrl,
},
);
return imageDataUrl; // Return original if format is invalid
}
final data = parts[1];
final bytes = base64Decode(data); final bytes = base64Decode(data);
// Decode image // Decode image