SDWebImage / SDWebImageSVGCoder

A SVG coder plugin for SDWebImage, using Apple's built-in framework
MIT License
103 stars 34 forks source link

Crash on svg image #43

Closed AndriiPetrovDev closed 1 year ago

AndriiPetrovDev commented 1 year ago

Try to open this image https://openseauserdata.com/files/b809fe0925eb3629bb1d3edb1fafcc88.svg SDWebImage crashes because "NSFont can't be nil"

dreampiggy commented 1 year ago

Seems SVG use a font which native iOS platform does not embed.

Does this a Objective-C exception (or C++ exception) which can be handled by our user level code ?

If so, we can add a protect here. To make it Load SVG failed but not crash your user app.

dreampiggy commented 1 year ago
font-family="宋体"
AndriiPetrovDev commented 1 year ago

It will be really nice.

AndriiPetrovDev commented 1 year ago

Can we solve such problems for all possible alphabets?

dreampiggy commented 1 year ago

Does this a Objective-C exception (or C++ exception) which can be handled by our user level code ?

Did you test this ?

osmantufekci commented 1 year ago

There is another crash, EXC_BADACCESS on SDCGSVGDocumentWriteToData method. But it happens only at first load, subsequent load attempt won't crash. I also tried with SDWebImageSVGNativeCoder but this time it shows the file as pure black.

This is the svg file; general

as text: general.txt

dreampiggy commented 1 year ago

SDCGSVGDocumentWriteToData is used to re-export UIImage to NSData. So why do you meanBut it happens only at first load, subsequent load attempt won't crash ?

I don't think these two is the same issue. SDWebImage itself should not re-encode SVG image to NSData if you don't specify this (using thumbnail or transformer)

Actually, the SVG export feature is not really useful in general, because SVG is vector image format. For the re-export, you can just save the data (download from SVG URL) and re-read it

dreampiggy commented 1 year ago

Is this logic bug ? Any demo can reproduce your But it happens only at first load, subsequent load attempt won't crash ?

For normal WebImage loading process, it should not trigger re-encode logic.

  1. Query Cache failed
  2. Download SVG Data
  3. Create UIImage (using CoreSVG)
  4. Store Data to Disk, UIImage to Memory
  5. Finish Callback