mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-14 14:57:28 -06:00
[bugfix] Update exif-terminator (fix png issue) (#2391)
* [bugfix] Update exif-terminator (fix png issue) * bump exif terminator * fix tests
This commit is contained in:
parent
6abe91ceb2
commit
0108463e7b
21 changed files with 752 additions and 830 deletions
68
vendor/github.com/superseriousbusiness/exif-terminator/png.go
generated
vendored
68
vendor/github.com/superseriousbusiness/exif-terminator/png.go
generated
vendored
|
|
@ -19,10 +19,9 @@
|
|||
package terminator
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
|
||||
pngstructure "github.com/dsoprea/go-png-image-structure/v2"
|
||||
pngstructure "github.com/superseriousbusiness/go-png-image-structure/v2"
|
||||
)
|
||||
|
||||
type pngVisitor struct {
|
||||
|
|
@ -45,49 +44,50 @@ func (v *pngVisitor) split(data []byte, atEOF bool) (int, []byte, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// check if the splitter has any new chunks in it that we haven't written yet
|
||||
chunkSlice := v.ps.Chunks()
|
||||
// Check if the splitter now has
|
||||
// any new chunks in it for us.
|
||||
chunkSlice, err := v.ps.Chunks()
|
||||
if err != nil {
|
||||
return advance, token, err
|
||||
}
|
||||
|
||||
// Write each chunk by passing it
|
||||
// through our custom write func,
|
||||
// which strips out exif and fixes
|
||||
// the CRC of each chunk.
|
||||
chunks := chunkSlice.Chunks()
|
||||
for i, chunk := range chunks {
|
||||
// look through all the chunks in the splitter
|
||||
if i > v.lastWrittenChunk {
|
||||
// we've got a chunk we haven't written yet! write it...
|
||||
if err := v.writeChunk(chunk); err != nil {
|
||||
return advance, token, err
|
||||
}
|
||||
// then remove the data
|
||||
chunk.Data = chunk.Data[:0]
|
||||
// and update
|
||||
v.lastWrittenChunk = i
|
||||
if i <= v.lastWrittenChunk {
|
||||
// Skip already
|
||||
// written chunks.
|
||||
continue
|
||||
}
|
||||
|
||||
// Write this new chunk.
|
||||
if err := v.writeChunk(chunk); err != nil {
|
||||
return advance, token, err
|
||||
}
|
||||
v.lastWrittenChunk = i
|
||||
|
||||
// Zero data; here you
|
||||
// go garbage collector.
|
||||
chunk.Data = nil
|
||||
}
|
||||
|
||||
return advance, token, err
|
||||
}
|
||||
|
||||
func (v *pngVisitor) writeChunk(chunk *pngstructure.Chunk) error {
|
||||
if err := binary.Write(v.writer, binary.BigEndian, chunk.Length); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := v.writer.Write([]byte(chunk.Type)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if chunk.Type == pngstructure.EXifChunkType {
|
||||
blank := make([]byte, len(chunk.Data))
|
||||
if _, err := v.writer.Write(blank); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := v.writer.Write(chunk.Data); err != nil {
|
||||
return err
|
||||
}
|
||||
// Replace exif data
|
||||
// with zero bytes.
|
||||
clear(chunk.Data)
|
||||
}
|
||||
|
||||
if err := binary.Write(v.writer, binary.BigEndian, chunk.Crc); err != nil {
|
||||
return err
|
||||
}
|
||||
// Fix CRC of each chunk.
|
||||
chunk.UpdateCrc32()
|
||||
|
||||
return nil
|
||||
// finally, write chunk to writer.
|
||||
_, err := chunk.WriteTo(v.writer)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue