There are two concepts: attachments (see xf_attachment table) and attachment data (see xf_attachment_data table).
Attachment data represents a single file. Attachments represent which content the data is attached to.
When media is mirrored from a forum into the gallery there are two attachments but they each use the same attachment data and therefore only a single file is stored.