randy408 / libspng

Simple, modern libpng alternative
https://libspng.org
BSD 2-Clause "Simplified" License
742 stars 75 forks source link

Missing check in function check_time #265

Closed 3iang closed 10 months ago

3iang commented 10 months ago

Describe the bug A clear and concise description of what the bug is. RFC1123 limits the year field should be a 4-digit number and the limitation is implemented in libpng. However, if it is on purpose in libspng, just ignore this issue.

static int check_time(const struct spng_time *time)
{
    if(time == NULL) return 1;
+   if(time->year > 9999) return 1;
    if(time->month == 0 || time->month > 12) return 1;
    if(time->day == 0 || time->day > 31) return 1;
    if(time->hour > 23) return 1;
    if(time->minute > 59) return 1;
    if(time->second > 60) return 1;

    return 0;
}

NOTE: Bugs that can cause a crash or memory leak should not be reported on GitHub! Send an e-mail to contact@libspng.org instead.

To Reproduce Steps to reproduce the behavior: code snippet, PNG file (if applicable), error message(s).

Expected behavior A clear and concise description of what you expected to happen.

return 1 when year > 9999

Platform (please complete the following information):

Additional context Add any other context about the problem here.

randy408 commented 10 months ago

RFC1123 limits the year field should be a 4-digit number and the limitation is implemented in libpng.

Could you reference where this check is made? I don't see it in v1.6.40: https://github.com/glennrp/libpng/blob/v1.6.40/pngset.c#L956-L977

It's better to avoid adding minor error checks that aren't already in libpng, they create interoperability issues.