Skip to content

Commit

Permalink
Pubmatic: Fix Shared Memory Overwriting (prebid#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon authored and Veronika Solovei committed Mar 25, 2021
1 parent 525f54d commit d1ac8a2
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ func validateAdSlot(adslot string, imp *openrtb.Imp) error {

//In case of video, size could be derived from the player size
if imp.Banner != nil {
imp.Banner.H = openrtb.Uint64Ptr(uint64(height))
imp.Banner.W = openrtb.Uint64Ptr(uint64(width))
imp.Banner = assignBannerHeightAndWidth(imp.Banner, uint64(height), uint64(width))
}
} else {
return errors.New(fmt.Sprintf("Invalid adSlot %v", adSlotStr))
Expand All @@ -428,25 +427,25 @@ func validateAdSlot(adslot string, imp *openrtb.Imp) error {
return nil
}

func assignBannerSize(banner *openrtb.Banner) error {
if banner == nil {
return nil
}

func assignBannerSize(banner *openrtb.Banner) (*openrtb.Banner, error) {
if banner.W != nil && banner.H != nil {
return nil
return banner, nil
}

if len(banner.Format) == 0 {
return errors.New(fmt.Sprintf("No sizes provided for Banner %v", banner.Format))
return nil, errors.New(fmt.Sprintf("No sizes provided for Banner %v", banner.Format))
}

banner.W = new(uint64)
*banner.W = banner.Format[0].W
banner.H = new(uint64)
*banner.H = banner.Format[0].H
return assignBannerHeightAndWidth(banner, banner.Format[0].H, banner.Format[0].H), nil
}

return nil
func assignBannerHeightAndWidth(banner *openrtb.Banner, h uint64, w uint64) *openrtb.Banner {
bannerCopy := *banner

bannerCopy.W = openrtb.Uint64Ptr(w)
bannerCopy.H = openrtb.Uint64Ptr(h)

return &bannerCopy
}

// parseImpressionObject parse the imp to get it ready to send to pubmatic
Expand Down Expand Up @@ -489,9 +488,11 @@ func parseImpressionObject(imp *openrtb.Imp, wrapExt *string, pubID *string) err
}

if imp.Banner != nil {
if err := assignBannerSize(imp.Banner); err != nil {
bannerCopy, err := assignBannerSize(imp.Banner)
if err != nil {
return err
}
imp.Banner = bannerCopy
}

if pubmaticExt.Keywords != nil && len(pubmaticExt.Keywords) != 0 {
Expand Down

0 comments on commit d1ac8a2

Please sign in to comment.