If you have an attachment that has two versions, 1.1 and 1.2, where 1.1 corresponds to document version X and 1.2 to document version Y, then calling getContentInputStream() on the 1.1 version obtained from X will return the content from version 1.2.
The reasons is this:
- we store only the latest version of an attachment in xwikiattachment_content (where the content is identified by the file name and the document reference)
- the rest of the versions are stored in xwikiattachment_archive
- if the attachment content is not loaded or set then getContentInputStream() always loads the content from xwikiattachment_content (so the latest stored version).