Opened 6 years ago

Closed 6 years ago

#3171 closed defect (invalid)

avio_close() misuses AVIOContext.opaque field

Reported by: achurch Owned by:
Priority: normal Component: avformat
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

(Note: the following is true as of git e78d038187)

In avio.h, the AVIOContext.opaque field is documented as "A private pointer, passed to the read/write/seek/... functions", and avio_alloc_context() takes an "opaque" parameter which is similarly documented "An opaque pointer to user-specific data" and stored directly into the created structure's opaque field. However, avio_close() treats that field as a URLContext pointer:

int avio_close(AVIOContext *s)
{

URLContext *h;
...
h = s->opaque;
...
return ffurl_close(h);

}

If a user-created AVIOContext makes use of the opaque field as documented, avio_close() may crash, inappropriately free memory, etc. when it interprets the user's opaque data as a URLContext structure.

Change History (2)

comment:1 Changed 6 years ago by achurch

Never mind, apparently I was misusing av_close() (maybe leftover code from an old libavformat version?). Please ignore/close this bug.

comment:2 Changed 6 years ago by Cigaes

  • Resolution set to invalid
  • Status changed from new to closed
This function can only be used if s was opened by avio_open().

Therefore, avio_close() should not be called on an user-created AVIOContext that makes use of the opaque field.

Note: See TracTickets for help on using tickets.