You can do this with policy based routing, although this is an example of filtering any packet bigger than 512 bytes, it does not make your router fragment packets to 512 bytes.
ip access-list extended Filter
permit ip any any
router-map Filter
match ip address Filter
match length 1 512
set interface Null0
On the inbound interface:
ip policy route-map filter
This method will only work on inbound traffic coming in through the interface you have set the policy on
If you want to filter outbound traffic from the router, instead of an interface level command, use the following global command:
ip local policy route-map filter
You can also match only certain traffic by modifying what the access-list matches, or if using the global level command, and you want to filter outbound traffic only on a certain interface, you can do an extra `match