@@ -951,10 +951,18 @@ def _build_month_line(self, weeks_data: list) -> str:
951951
952952 try :
953953 date_obj = datetime .fromisoformat (first_day )
954- except ValueError :
954+ # Validate year is in reasonable range to avoid C int overflow
955+ if date_obj .year < 1900 or date_obj .year > 9999 :
956+ continue
957+ except (ValueError , OverflowError ):
955958 continue
956959
957- month_abbr = date_obj .strftime ('%b' )
960+ try :
961+ month_abbr = date_obj .strftime ('%b' )
962+ except (ValueError , OverflowError ):
963+ # strftime can fail with years outside 1900-9999
964+ continue
965+
958966 if month_abbr != last_month :
959967 month_chars .append (month_abbr )
960968 last_month = month_abbr
@@ -986,8 +994,11 @@ def _build_month_line_spaced(self, weeks_data: list) -> str:
986994
987995 try :
988996 date_obj = datetime .fromisoformat (first_day )
997+ # Validate year is in reasonable range to avoid C int overflow
998+ if date_obj .year < 1900 or date_obj .year > 9999 :
999+ continue
9891000 current_month = date_obj .month
990- except ValueError :
1001+ except ( ValueError , OverflowError ) :
9911002 continue
9921003
9931004 # Check if this is a new month
@@ -1003,6 +1014,9 @@ def _build_month_line_spaced(self, weeks_data: list) -> str:
10031014 prev_date_obj = datetime .fromisoformat (
10041015 prev_first_day
10051016 )
1017+ # Validate year is in reasonable range
1018+ if prev_date_obj .year < 1900 or prev_date_obj .year > 9999 :
1019+ continue
10061020 prev_month = prev_date_obj .month
10071021 if current_month != prev_month :
10081022 # New month - add spacing and month name
@@ -1016,7 +1030,7 @@ def _build_month_line_spaced(self, weeks_data: list) -> str:
10161030 needed_space = max (1 , calc )
10171031 month_line += " " * needed_space
10181032 month_line += month_name
1019- except ValueError :
1033+ except ( ValueError , OverflowError ) :
10201034 pass
10211035
10221036 return f" { month_line } "
@@ -1298,8 +1312,11 @@ def _format_date(self, date_string: str) -> str:
12981312 """
12991313 try :
13001314 dt = datetime .fromisoformat (date_string .replace ('Z' , '+00:00' ))
1315+ # Validate year is in reasonable range to avoid C int overflow
1316+ if dt .year < 1900 or dt .year > 9999 :
1317+ return date_string
13011318 return dt .strftime ('%B %d, %Y' )
1302- except (ValueError , AttributeError ):
1319+ except (ValueError , AttributeError , OverflowError ):
13031320 return date_string
13041321
13051322 def _get_contribution_block (self , count : int ) -> str :
0 commit comments