The bug
When the player's base max health is reduced using /attribute, their current health (stored on the server) is not always reduced accordingly. (There have been reports in the past that this bug occurs whenever the player's total max health is reduced, including using attribute modifiers, but as of the 1.20.2 snapshots I can only reproduce this by modifying the base value using /attribute.)
Reproduction
Setup
This bug occurs inconsistently and can be hard to detect when it occurs unless you're paying close attention, so it's preferable to have a dedicated testing setup. Let's start with a few of commands:
/gamerule doImmediateRespawn true
/gamerule keepInventory true
/gamerule naturalRegeneration false
/spawnpoint @s ~ ~ ~
Now let's make our current health value visible in the sidebar:
/scoreboard objectives add health health
/scoreboard objectives setdisplay sidebar health
/kill @s
And, for extra visibility, let's make particles emanate from ourselves when our current health exceeds our max health. First we run the following:
/scoreboard objectives add temp dummy
Then we put the following in a powered repeating command block:
execute as @p store result score @s temp run attribute @s minecraft:generic.max_health get 1.0
And the following in an unconditional, always-active chain command block pointing away from the repeating one:
execute as @p at @s if score @s health > @s temp run particle minecraft:glow ~ ~ ~ 0.2 0 0.2 0.2 10
Now let's set up some impulse command blocks which can cause the bug to occur. Place a button on each one, and make sure they aren't adjacent to each other.
attribute @p minecraft:generic.max_health base set 1
attribute @p minecraft:generic.max_health base set 20
attribute @p minecraft:generic.max_health base set 30
Finally, we need a command block to heal ourselves to full in case we've failed to repro and want to try again. Place a button on this one too.
effect give @p minecraft:instant_health 1 20 true
Reproducing the bug
Go into survival mode. Using the command blocks you just set up, set your base max health to 30 and heal yourself to full. Try reducing your max health, first to 20, then to 1. If you get particles and notice that the health value in the sidebar exceeds the hearts on your screen, the bug has occurred! If not, start over from the beginning of this paragraph.
Once you've repro'd successfully, set your max health to 30 again. As the particles cease, note how while you do regain some black hearts, the amount of red hearts remains unchanged. I assume this is because the client is sent an "update max health" packet but the server sees no need to send an "update current health" packet since it did not know the client was out of sync.
Being hurt or healed while the bug is occurring will fix it.
Remarks
NBT state has no effect
Due to MC-197818, the player's NBT does not accurately reflect the state of their attributes. This does not seem to affect whether or not the bug occurs at a particular point in time, but if desired, you can run /kill @s
to trigger that issue and MC-179940, removing the max health attribute from your NBT and starting over again with 20 health.
Attribute modifiers have no effect (anymore)
Some past reports indicate that it was possible to get the player's current health to be higher than their max health using attribute modifiers. I tried to reproduce this by playing around with the following items during the tests mentioned above, but ultimately I did not encounter any inexplicable behavior.
/give @s stick{AttributeModifiers:[{AttributeName:"minecraft:generic.max_health",Name:"health-",Slot:"mainhand",Amount:-10,Operation:0,UUID:[I;0,1111,0,111111]}],display:{Name:'"Health Reduction"'}}
/give @s blaze_rod{AttributeModifiers:[{AttributeName:"minecraft:generic.max_health",Name:"health+",Slot:"mainhand",Amount:10,Operation:0,UUID:[I;0,1111,0,111112]}],display:{Name:'"Health Boost"'}}
/give @s golden_helmet{AttributeModifiers:[{AttributeName:"minecraft:generic.max_health",Name:"health++",Slot:"head",Amount:20,Operation:0,UUID:[I;0,1111,0,111113]}],display:{Name:'"Mega Health Boost"'}}
Linked issues
is duplicated by 28
relates to 2
Attachments
Comments 27

Is this still a concern in the latest Minecraft version 14w30c? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Relates to: MC-19690
Confirmed for
14w30c
14w31a
Minecraft 1.8-pre 1
How to reproduce:
Perform this command
/scoreboard objectives add Health health
Then this
/scoreboard objectives setdisplay sidebar Health
Give yourself an item with the max healt attribute and select it
/give @p dirt 1 0 {AttributeModifiers:[0:{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:10000,Operation:0,UUIDLeast:894654,UUIDMost:2872},1:{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:2.5,Operation:1,UUIDLeast:111113,UUIDMost:1111},2:{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:40,Operation:0,UUIDLeast:111113,UUIDMost:1111}],display:{Name:"GodSword 2.1",Lore:["The Ultimate Power","By Vengeur69"]}}
Your Health score should now be 60, now deselect it
Your Health score is still 60, the game changes this back to 20 as soon as you get damage, but does NOT reduce your health lower than 20 because of the damage
I know some people could say that this is a bug with the scoreboard, but it is not, you can proof this with programmes like the "NBT-Explorer" this shows you the same like the scoreboard does
Confirmed for 1.8.2 pre-4. Also occurs when using an item that lowers your max health.

Confirmed for
15w37a
Can confirm in 1.18.1.
Can confirm in 1.18.2 and 22w18a.
Can confirm in 1.19.
Can confirm in 1.19.2

As of 23w31a this bug seems to only happen when modifying the base health to a value less than 20 with /attribute, and even then somewhat infrequently. I've performed the same steps over and over and cannot discern any pattern behind the occurences.
Additionally, it seems that when this bug does occur and the attribute command is run again to reset the player's max health to 20, the heart meter will remain stuck at the lower value until the next time the player takes damage; any healing effects will not be reflected, probably because the server sees no reason to send such a packet to the client when the health is already full.
Note, that once you delesected the item and fall back under 20 Health, it will stop increasing your health at 20.